• <Helps for GetStart>
  • CSPro User's Guide
    • The CSPro System
    • Data Dictionary Module
    • The CSPro Language
    • Data Entry Module
    • Batch Editing Applications
    • Tabulation Applications
    • CSPro Statements and Functions
      • Statement Format Symbols
      • Alphabetical List of Functions and Statements
      • List of Reserved Words
      • Deprecated Features
      • Declaration Statements
      • Array Object
      • Audio Object
      • Barcode and QR Codes
      • Document Object
      • File Object
      • Freq Object
        • Freq Statement (Named)
        • Frequency Formatting Options
        • Freq.Tally Function
        • Freq.Clear Function
        • Freq.Save Function
        • Freq.View Function
      • Geometry Object
      • HashMap Object
      • Image Object
      • List Object
      • Map Object
      • Path
      • Pff Object
      • SystemApp Object
      • ValueSet Object
      • Program Control Statements
      • Assignment Statements
      • Data Entry Statements and Functions
      • Batch Edit Statements
      • Numeric Functions
      • String Functions
      • Multiple Occurrence Functions
      • General Functions
      • Date and Time Functions
      • External File Functions
      • Synchronization Functions
      • Export Attributes
    • Templated Reporting System
    • HTML and JavaScript Integration
    • Appendix
  • <Helps for CSEntry>
  • <Helps for CSBatch>
  • <Helps for CSTab>
  • <Helps for DataViewer>
  • <Helps for TextView>
  • <Helps for TblView>
  • <Helps for TRSWin>
  • <Helps for CSDeploy>
  • <Helps for CSPack>
  • <Helps for CSFreq>
  • <Helps for CSSort>
  • <Helps for CSExport>
  • <Helps for CSReFmt>
  • <Helps for CSDiff>
  • <Helps for CSConcat>
  • <Helps for TRSSetup>
  • <Helps for ParadataViewer>
  • <Helps for ParadataConcat>
  • <Helps for CSIndex>
  • <Helps for Excel2CSPro>
  • <Helps for CSWeb>

Freq Statement (Named)

Format
freq freq_name
include(variables_to_tabulate)
ʃexclude(variables_not_to_tabulate)ʅ
ʃdisjointʅ
ʃbreakdown(length)ʅ
ʃformatting_optionsʅ
;
Description
The freq statement creates a freq object with the name freq_name. The freq name must be unique and must contain only letters, numbers, or the underscore character. The name must begin with a letter. You can declare freqs globally in PROC GLOBAL or locally in functions or procedures.
The freq object is used to create frequencies that will be written to the frequencies file (using freq.save) or displayed in an embedded web browser (using freq.view).
Freq objects are similar to unnamed frequencies except that you control when they are tallied (using the freq.tally function). Because of this, the universe and weight commands, which are part of the unnamed frequencies specification, are not available. You can control the universe (using an if statement) and you can control the weight by passing an argument to the freq.tally function.
Specifying Variables to Tabulate
The include command is used to specify what variables should be tabulated. At least one frequency table will be created for every variable specified in the include list. The variables_to_tabulate is a list of variables, separated by commas, that can include:
  • Dictionary names: dictionaries, records, and items
  • Form names: forms, groups, and blocks
  • Logic names: numeric and string variables
The optional exclude command is used to specify variables that should be removed from the inclusion list. The variables_not_to_tabulate is a list of variables as defined above. The exclude command is particularly useful when including records. For example, if you want to tabulate most items on a record with a couple exceptions, you might code:
include(PERSON_REC)
exclude(P25_RELIGION, P26_TRIBE)
When including or excluding a name that may contain more than one variable—dictionaries, records, forms, groups, and blocks—CSPro uses a rule to determine whether items contained in that grouping should be included in the list of variables to tabulate:
Default rule: Include the item if it has a value set; if no value set is defined, then include the item if it has length 1 - 4.
You can override the default selection by adding one or more of these flags to the include/exclude list:
FlagInclude/Exclude All...
numericnumeric items
floatnumeric items with decimals
integernumeric items without decimals
longnumeric items without decimals and length 3 - 15
shortnumeric items without decimals and length 1 - 2
alphaalphanumeric items
These six flags will never include items that have subitems. You can use a combination of flags; for example, this would include all items from PERSON_REC with the exception of items that have subitems (though the subitems would be included).
include(numeric, alpha, PERSON_REC)
Leaving the include list empty is as if you coded the primary dictionary name. For example:
include()
// may be translated to:
include(CENSUS_DICT)
If you do not need to exclude any variables, the include command is optional. For example, these unnamed frequency statements are the same:
freq include(P03_SEX);
freq(P03_SEX);
Handling Variable Occurrences
By default, when frequencies are tallied for a multiply-occurring item, all of the occurrences of the item are tallied. For example, assuming that P03_SEX is on a record with 50 occurrences, coding this will tally all defined occurrences of P03_SEX:
freq include(P03_SEX);
If the first house is vacant, then no sex values are tallied; if the second house has three people, then three sex values are tallied; and so on.
If you would like to tally a specific occurrence, you can specify the occurrence in the include/exclude list. For example, this would create two tables, one for all sex occurrences, and one for the head's sex (assuming that the head is the first occurrence):
freq include(P03_SEX, P03_SEX(1));
You can specify occurrence values when using items or records. PERSON_REC(1), for example, would create tables for the first occurrence of the items in PERSON_REC. If you specify an occurrence, the value will be tallied regardless of whether the occurrence exists. For example, while P03_SEX would not tally vacant households, P03_SEX(1) will include tallies of blank values for vacant households.
An optional command, disjoint, is a shortcut way of indicating that a frequency table should be created for every occurrence of a variable. For example, this code would create a table for each of the occurrences of P03_SEX, resulting in 50 tables (for occurrence 1, occurrence 2, and so on until occurrence 50):
freq include(P03_SEX)
     
disjoint;
When using disjoint, you can use (*) as an occurrence to specify that you would like to ignore the disjoint setting. For example, this code would create 49 tables (for the combined occurrences, for occurrence 3, occurrence 4, and so on until occurrence 50).
freq include(P03_SEX(*), P03_SEX)
     
exclude(P03_SEX(1), P03_SEX(2))
     
disjoint;
Alphanumeric Breakdown
The optional command breakdown allows you to control how alphanumeric items and string variables are tallied. A positive numeric constant, length, specifies a number used to split these values before tallying. This can be useful when creating frequencies for data collected using checkboxes. For example, assuming CHECKBOX_FIELD occurs twice, first as "AB" and then as "BC":
freq include(CHECKBOX_FIELD); // results in: "AB" (1)
                              //             "BC" (1)

freq include(CHECKBOX_FIELD)  // results in:  "A" (1)
     breakdown(1);            //              "B" (2)
                              //              "C" (1)
Additional Commands
Optional formatting options allow you to control how the frequency tables are generated. The formatting options include the following commands: valueset, distinct, vset, heading, stat, percentiles, nofreq, decimals, sort, nonetpercents, and pagelength.
Example
PROC GLOBAL

// create a freq object that will tally the sex and age of
// the first occurrence (the head)
freq head_sex_age_freq(P03_SEX(1), P04_AGE(1));

PROC CENSUS_DICTIONARY_FF

   
// save the frequency, formatting the ages using a
    // 5-year value set
    head_sex_age_freq.save()
                     
valueset(P04_AGE_5YEAR_VS);

PROC QUEST

   
// only tally households that are not vacant
    if count(PERSON_REC) > 0 then
       
head_sex_age_freq.tally();
   
endif;
See also: Freq Object, Freq Statement (Unnamed), Frequency Formatting Options