Frequency and Crosstabulation Analysis Action Set
Frequency Tables
This section contains PROC CAS code.
Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts. A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.
The example explores ways that you can use the freqTab action in the freqTab action set to produce one-way to n-way frequency and crosstabulation tables.
The following DATA step creates the mycas.Color data table, which provides the eye and hair color of children from two different regions of Europe, in your CAS session. Instead of recording one observation per child, the data are recorded as cell counts, where the variable Count contains the number of children who exhibit each of the 15 eye color and hair color combinations. This DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.Color;
input Region Eyes $ Hair $ Count @@;
label Eyes ='Eye Color'
Hair ='Hair Color'
Region='Geographic Region';
datalines;
1 blue fair 23 1 blue red 7 1 blue medium 24
1 blue dark 11 1 green fair 19 1 green red 7
1 green medium 18 1 green dark 14 1 brown fair 34
1 brown red 5 1 brown medium 41 1 brown dark 40
1 brown black 3 2 blue fair 46 2 blue red 21
2 blue medium 44 2 blue dark 40 2 blue black 6
2 green fair 50 2 green red 31 2 green medium 37
2 green dark 23 2 brown fair 56 2 brown red 42
2 brown medium 53 2 brown dark 54 2 brown black 13
1 . medium 4 1 brown . 6 1 green black .
;
Producing Frequency and Crosstabulation Tables
The following PROC CAS statements use the freqTab action in the freqTab action set to produce frequency and crosstabulation tables:
proc cas;
action freqTab.freqTab /
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair',
{vars={'Eyes', 'Hair'}},
{vars='Region', cross={'Eyes', 'Hair'}}
};
run;
The tabulate parameter enables you to specify the frequency and crosstabulation tables to produce. This parameter defines a list of terms that are enclosed in braces and separated by commas. Each of these terms contains a list of variables defined by the vars subparameter and optionally a list of variables defined by the cross subparameter. In this example, the terms are {vars={’Eyes’}}, {vars={’Hair’}}, {vars={’Eyes’, ’Hair’}}, and {vars={’Region’}, cross={’Eyes’, ’Hair’}}. These terms define the frequency and crosstabulation tables to produce that correspond to the following syntax that you would use in the FREQ procedure in SAS/STAT:
tables Eyes Hair Eyes*Hair Region*(Eyes Hair);
If a term contains only a vars subparameter and the list that the vars subparameter defines consists of only a single variable, then you can directly specify the variable in the tabulate parameter without the enclosing braces. This type of simplification is a general property of action syntax that is referred to as "coercion." You can exploit coercion to simplify the specification {vars={’Eyes’}} to be simply ’Eyes’. You can also use coercion to simplify the specification of the vars subparameter when the list within braces that it defines consists of a single string. In this case, you can omit the braces and specify the string directly in the vars subparameter. Thus the term {vars={’Region’}, cross={’Eyes’, ’Hair’}} can be specified as {vars=’Region’, cross={’Eyes’, ’Hair’}}.
You define a single variable in the vars subparameter to produce a one-way frequency table. To produce two-way to multiway crosstabulation tables, you define at least two variables in the vars subparameter. The values of the last variable that is defined in the vars subparameter form the crosstabulation table columns. The values of the next-to-last variable form the rows. Each level (or combination of levels) of the other variables forms one stratum. By default, the freqTab action displays two-way and multiway tables in CROSSLIST format, where a separate two-way crosstabulation table is generated for each stratum of a multiway table.
When you specify the cross subparameter along with the vars subparameter, each pair of variables (one from the vars subparameter and the other from the cross subparameter, in this order) defines a two-way crosstabulation table to produce. So the specification of {vars=’Region’, cross={’Eyes’, ’Hair’}} defines two crosstabulation tables to produce: Region by Eyes and Region by Hair.
The default output from this analysis is presented in Output 11.1.1 through Output 11.1.3.
Output 11.1.1 displays the "Number of Observations" and "Variable Level Information" tables. The "Number of Observations" table indicates that there are 30 observations in the input data and 29 of them are used in the analysis. The last observation is not used in the analysis because the value of the weight variable Count is missing. The "Variable Level Information" table shows the level information for all variables that are defined in the tabulate parameter.
Output 11.1.1: Number of Observations and Variable Level Information
| Number of Observations Read | 30 |
|---|---|
| Number of Observations Used | 29 |
| Sum of Weights | 772 |
| Variable Level Information | |||
|---|---|---|---|
| Variable | Label | Levels | Values |
| Eyes | Eye Color | 3 | blue brown green |
| Hair | Hair Color | 5 | black dark fair medium red |
| Region | Geographic Region | 2 | 1 2 |
Output 11.1.2 displays the two one-way frequency tables that the freqTab action produces: one showing the frequency distribution of eye color and the other showing the frequency distribution of hair color. By default, the variable values are arranged in ascending order based on their internal (unformatted) values. The frequency of observations that have missing values is displayed following each table.
Output 11.1.2: Frequency Tables
| Eye Color | ||||
|---|---|---|---|---|
| Eyes | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| blue | 222 | 28.91 | 222 | 28.91 |
| brown | 347 | 45.18 | 569 | 74.09 |
| green | 199 | 25.91 | 768 | 100.00 |
| Frequency Missing = 4 | ||||
| Hair Color | ||||
|---|---|---|---|---|
| Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| black | 22 | 2.87 | 22 | 2.87 |
| dark | 182 | 23.76 | 204 | 26.63 |
| fair | 228 | 29.77 | 432 | 56.40 |
| medium | 221 | 28.85 | 653 | 85.25 |
| red | 113 | 14.75 | 766 | 100.00 |
| Frequency Missing = 6 | ||||
Output 11.1.3 displays the three crosstabulation tables that the freqTab action produces in CROSSLIST format: Eyes by Hair, which is defined by the specification of {vars={’Eyes’, ’Hair’}}; and Region by Eyes and Region by Hair, which are defined by the specification of {vars=’Region’, cross={’Eyes’, ’Hair’}}. In the crosstabulation of Eyes and Hair, the values of Eyes define the table rows, and the values of Hair define the table columns. In the crosstabulation tables of Region by Eyes and Region by Hair, the values of Region define the table rows, and the values of Eyes and Hair define the table columns, respectively.
Output 11.1.3: Crosstabulation Tables
| Table of Eyes by Hair | |||||
|---|---|---|---|---|---|
| Eyes | Hair | Frequency | Percent | Row Percent | Column Percent |
| blue | black | 6 | 0.79 | 2.70 | 27.27 |
| dark | 51 | 6.69 | 22.97 | 28.02 | |
| fair | 69 | 9.06 | 31.08 | 30.26 | |
| medium | 68 | 8.92 | 30.63 | 31.34 | |
| red | 28 | 3.67 | 12.61 | 24.78 | |
| Total | 222 | 29.13 | 100.00 | . | |
| brown | black | 16 | 2.10 | 4.69 | 72.73 |
| dark | 94 | 12.34 | 27.57 | 51.65 | |
| fair | 90 | 11.81 | 26.39 | 39.47 | |
| medium | 94 | 12.34 | 27.57 | 43.32 | |
| red | 47 | 6.17 | 13.78 | 41.59 | |
| Total | 341 | 44.75 | 100.00 | . | |
| green | dark | 37 | 4.86 | 18.59 | 20.33 |
| fair | 69 | 9.06 | 34.67 | 30.26 | |
| medium | 55 | 7.22 | 27.64 | 25.35 | |
| red | 38 | 4.99 | 19.10 | 33.63 | |
| Total | 199 | 26.12 | 100.00 | . | |
| Total | black | 22 | 2.89 | . | 100.00 |
| dark | 182 | 23.88 | . | 100.00 | |
| fair | 228 | 29.92 | . | 100.00 | |
| medium | 217 | 28.48 | . | 100.00 | |
| red | 113 | 14.83 | . | 100.00 | |
| Total | 762 | 100.00 | . | . | |
| Frequency Missing = 10 | |||||
| Table of Region by Eyes | |||||
|---|---|---|---|---|---|
| Region | Eyes | Frequency | Percent | Row Percent | Column Percent |
| 1 | blue | 65 | 8.46 | 25.79 | 29.28 |
| brown | 129 | 16.80 | 51.19 | 37.18 | |
| green | 58 | 7.55 | 23.02 | 29.15 | |
| Total | 252 | 32.81 | 100.00 | . | |
| 2 | blue | 157 | 20.44 | 30.43 | 70.72 |
| brown | 218 | 28.39 | 42.25 | 62.82 | |
| green | 141 | 18.36 | 27.33 | 70.85 | |
| Total | 516 | 67.19 | 100.00 | . | |
| Total | blue | 222 | 28.91 | . | 100.00 |
| brown | 347 | 45.18 | . | 100.00 | |
| green | 199 | 25.91 | . | 100.00 | |
| Total | 768 | 100.00 | . | . | |
| Frequency Missing = 4 | |||||
| Table of Region by Hair | |||||
|---|---|---|---|---|---|
| Region | Hair | Frequency | Percent | Row Percent | Column Percent |
| 1 | black | 3 | 0.39 | 1.20 | 13.64 |
| dark | 65 | 8.49 | 26.00 | 35.71 | |
| fair | 76 | 9.92 | 30.40 | 33.33 | |
| medium | 87 | 11.36 | 34.80 | 39.37 | |
| red | 19 | 2.48 | 7.60 | 16.81 | |
| Total | 250 | 32.64 | 100.00 | . | |
| 2 | black | 19 | 2.48 | 3.68 | 86.36 |
| dark | 117 | 15.27 | 22.67 | 64.29 | |
| fair | 152 | 19.84 | 29.46 | 66.67 | |
| medium | 134 | 17.49 | 25.97 | 60.63 | |
| red | 94 | 12.27 | 18.22 | 83.19 | |
| Total | 516 | 67.36 | 100.00 | . | |
| Total | black | 22 | 2.87 | . | 100.00 |
| dark | 182 | 23.76 | . | 100.00 | |
| fair | 228 | 29.77 | . | 100.00 | |
| medium | 221 | 28.85 | . | 100.00 | |
| red | 113 | 14.75 | . | 100.00 | |
| Total | 766 | 100.00 | . | . | |
| Frequency Missing = 6 | |||||
Producing Crosstabulation Tables in LIST Format
The freqTab action also supports displaying crosstabulation tables in LIST format, which presents the entire multiway crosstabulation in a single table. The following code shows how you request crosstabulation tables in LIST format by using the tabDisplay parameter in the freqTab action. Because PROC CAS is an interactive procedure, it is not necessary to resubmit the PROC CAS statement.
action freqTab.freqTab /
table='Color',
weight='Count',
tabDisplay='LIST',
tabulate={{vars={'Eyes', 'Hair'}},
{vars={'Region', 'Eyes', 'Hair'}}
};
run;
In this case, coercion is used to simplify the specification of the tabDisplay parameter when the optional subparameters are not needed. The uncoerced version of the tabDisplay specification is tabDisplay={format=’LIST’}. If you use coercion, this simplifies to tabDisplay=’LIST’.
Output 11.1.4 shows the two crosstabulation tables in LIST format. Unlike the default CROSSLIST format, in LIST format the crosstabulation tables do not display row percentages and column percentages.
Output 11.1.4: Crosstabulation Tables in LIST Format
| Eyes | Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|---|
| blue | black | 6 | 0.79 | 6 | 0.79 |
| blue | dark | 51 | 6.69 | 57 | 7.48 |
| blue | fair | 69 | 9.06 | 126 | 16.54 |
| blue | medium | 68 | 8.92 | 194 | 25.46 |
| blue | red | 28 | 3.67 | 222 | 29.13 |
| brown | black | 16 | 2.10 | 238 | 31.23 |
| brown | dark | 94 | 12.34 | 332 | 43.57 |
| brown | fair | 90 | 11.81 | 422 | 55.38 |
| brown | medium | 94 | 12.34 | 516 | 67.72 |
| brown | red | 47 | 6.17 | 563 | 73.88 |
| green | dark | 37 | 4.86 | 600 | 78.74 |
| green | fair | 69 | 9.06 | 669 | 87.80 |
| green | medium | 55 | 7.22 | 724 | 95.01 |
| green | red | 38 | 4.99 | 762 | 100.00 |
| Frequency Missing = 10 | |||||
| Region | Eyes | Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|---|---|
| 1 | blue | dark | 11 | 1.44 | 11 | 1.44 |
| 1 | blue | fair | 23 | 3.02 | 34 | 4.46 |
| 1 | blue | medium | 24 | 3.15 | 58 | 7.61 |
| 1 | blue | red | 7 | 0.92 | 65 | 8.53 |
| 1 | brown | black | 3 | 0.39 | 68 | 8.92 |
| 1 | brown | dark | 40 | 5.25 | 108 | 14.17 |
| 1 | brown | fair | 34 | 4.46 | 142 | 18.64 |
| 1 | brown | medium | 41 | 5.38 | 183 | 24.02 |
| 1 | brown | red | 5 | 0.66 | 188 | 24.67 |
| 1 | green | dark | 14 | 1.84 | 202 | 26.51 |
| 1 | green | fair | 19 | 2.49 | 221 | 29.00 |
| 1 | green | medium | 18 | 2.36 | 239 | 31.36 |
| 1 | green | red | 7 | 0.92 | 246 | 32.28 |
| 2 | blue | black | 6 | 0.79 | 252 | 33.07 |
| 2 | blue | dark | 40 | 5.25 | 292 | 38.32 |
| 2 | blue | fair | 46 | 6.04 | 338 | 44.36 |
| 2 | blue | medium | 44 | 5.77 | 382 | 50.13 |
| 2 | blue | red | 21 | 2.76 | 403 | 52.89 |
| 2 | brown | black | 13 | 1.71 | 416 | 54.59 |
| 2 | brown | dark | 54 | 7.09 | 470 | 61.68 |
| 2 | brown | fair | 56 | 7.35 | 526 | 69.03 |
| 2 | brown | medium | 53 | 6.96 | 579 | 75.98 |
| 2 | brown | red | 42 | 5.51 | 621 | 81.50 |
| 2 | green | dark | 23 | 3.02 | 644 | 84.51 |
| 2 | green | fair | 50 | 6.56 | 694 | 91.08 |
| 2 | green | medium | 37 | 4.86 | 731 | 95.93 |
| 2 | green | red | 31 | 4.07 | 762 | 100.00 |
| Frequency Missing = 10 | ||||||
Displaying Missing Value Frequencies
If an observation has a missing value for a variable contained in a term that is defined by the tabulate parameter, by default that observation is not included in the frequency or crosstabulation table. Also by default, observations that have missing values are not included in the computation of percentages and statistics. The freqTab action displays the frequency of observations that have missing values following each frequency or crosstabulation table.
If you want to include in the analysis the observations that have missing values for variables defined in the tabulate parameter, you can specify either the includeMissing parameter or the missingFreq subparameter in the tabDisplay parameter. When you specify the includeMissing parameter, missing values are treated as a valid level for all variables defined in the tabulate parameter and are included in computations of percentages and statistics. When you specify the missingFreq subparameter in the tabDisplay parameter, missing values are presented in one-way frequency tables or crosstabulation tables in LIST format but are not included in computations of percentages or statistics. The following code shows how you can include observations that have missing values in the analysis:
action freqTab.freqTab /
table='Color',
weight='Count',
tabDisplay='LIST',
includeMissing=true,
tabulate={'Eyes', {vars={'Eyes', 'Hair'}}};
run;
action freqTab.freqTab /
table='Color',
weight='Count',
tabDisplay={format='LIST', missingFreq=true},
tabulate={'Eyes', {vars={'Eyes', 'Hair'}}};
run;
Output 11.1.5 shows the one-way frequency table and the two-way table in LIST format when you specify the includeMissing parameter. The table displays the missing level, and the freqTab action includes this level when computing frequencies and percentages.
Output 11.1.5: Missing Values in Frequency Tables: Specifying the includeMissing Parameter
| Eye Color | ||||
|---|---|---|---|---|
| Eyes | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| 4 | 0.52 | 4 | 0.52 | |
| blue | 222 | 28.76 | 226 | 29.27 |
| brown | 347 | 44.95 | 573 | 74.22 |
| green | 199 | 25.78 | 772 | 100.00 |
| Eyes | Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|---|
| medium | 4 | 0.52 | 4 | 0.52 | |
| blue | black | 6 | 0.78 | 10 | 1.30 |
| blue | dark | 51 | 6.61 | 61 | 7.90 |
| blue | fair | 69 | 8.94 | 130 | 16.84 |
| blue | medium | 68 | 8.81 | 198 | 25.65 |
| blue | red | 28 | 3.63 | 226 | 29.27 |
| brown | 6 | 0.78 | 232 | 30.05 | |
| brown | black | 16 | 2.07 | 248 | 32.12 |
| brown | dark | 94 | 12.18 | 342 | 44.30 |
| brown | fair | 90 | 11.66 | 432 | 55.96 |
| brown | medium | 94 | 12.18 | 526 | 68.13 |
| brown | red | 47 | 6.09 | 573 | 74.22 |
| green | dark | 37 | 4.79 | 610 | 79.02 |
| green | fair | 69 | 8.94 | 679 | 87.95 |
| green | medium | 55 | 7.12 | 734 | 95.08 |
| green | red | 38 | 4.92 | 772 | 100.00 |
Output 11.1.6 shows the one-way frequency table and the two-way table in LIST format when you specify the missingFreq subparameter in the tabDisplay parameter. The table displays the missing level, but the freqTab action does not include its frequency when computing the total frequency and percentages.
Output 11.1.6: Missing Values in Frequency Tables: Specifying the missingFreq Parameter
| Eye Color | ||||
|---|---|---|---|---|
| Eyes | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| 4 | . | . | . | |
| blue | 222 | 28.91 | 222 | 28.91 |
| brown | 347 | 45.18 | 569 | 74.09 |
| green | 199 | 25.91 | 768 | 100.00 |
| Frequency Missing = 4 | ||||
| Eyes | Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
|---|---|---|---|---|---|
| medium | 4 | . | . | . | |
| blue | black | 6 | 0.79 | 6 | 0.79 |
| blue | dark | 51 | 6.69 | 57 | 7.48 |
| blue | fair | 69 | 9.06 | 126 | 16.54 |
| blue | medium | 68 | 8.92 | 194 | 25.46 |
| blue | red | 28 | 3.67 | 222 | 29.13 |
| brown | 6 | . | . | . | |
| brown | black | 16 | 2.10 | 238 | 31.23 |
| brown | dark | 94 | 12.34 | 332 | 43.57 |
| brown | fair | 90 | 11.81 | 422 | 55.38 |
| brown | medium | 94 | 12.34 | 516 | 67.72 |
| brown | red | 47 | 6.17 | 563 | 73.88 |
| green | dark | 37 | 4.86 | 600 | 78.74 |
| green | fair | 69 | 9.06 | 669 | 87.80 |
| green | medium | 55 | 7.22 | 724 | 95.01 |
| green | red | 38 | 4.99 | 762 | 100.00 |
| Frequency Missing = 10 | |||||
Specifying Variable Attributes
The freqTab action groups a variable’s values according to its formatted values, except for numeric variables for which no explicit format is provided. These numeric variables are grouped by their internal value. As with the LABEL and FORMAT statements that you can use with SAS procedures, you can use the attributes parameter to specify formats and labels for variables in the input CAS table. The freqTab action formats the variable values before grouping observations into the levels of a frequency or crosstabulation table. The following code shows how you can do this:
action freqTab.freqTab /
table='Color',
attributes={{name='Region', format='roman4.', label='European Region'}},
weight='Count',
tabulate='Region';
run;
The "Variable Level Information" table and the "One-Way Frequencies" table in Output 11.1.7 show that the freqTab action applies the specified format for the variable Region. The "One-Way Frequencies" table displays both the formatted and unformatted values of the variable Region. By default, the frequency or crosstabulation table lists the values of both character and numeric variables in ascending order based on internal (unformatted) variable values. To list the values in ascending order by formatted values, specify order=’FORMATTED’ in the freqTab action.
Output 11.1.7: Output with Variable Attributes Specified
| Variable Level Information | |||
|---|---|---|---|
| Variable | Label | Levels | Values |
| Region | European Region | 2 | I II |
| European Region | ||||
|---|---|---|---|---|
| Region | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| I | 256 | 33.16 | 256 | 33.16 |
| II | 516 | 66.84 | 772 | 100.00 |
Attributes that you specify for a variable in the attributes parameter override those same attributes for that variable in the input data. However, the input data attributes are unchanged after the action completes.
Using the display Parameter
The freqTab action supports a display parameter, which provides functionality that corresponds to that of ODS SELECT, ODS EXCLUDE, and ODS TRACE statements on a SAS client. The major advantage of the action’s display parameter is that you can use it with Lua, Python, and Java clients, for which the ODS system is not available. The following code shows how you can use the traceNames subparameter of the display parameter to obtain the paths of the tables that the freqTab action produces:
action freqTab.freqTab /
table='Color',
weight='Count',
display={traceNames=true},
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}};
run;
This code produces the following notes in the SAS log:
NOTE: Name:'NObs' Label:'Number of Observations' Path:'NObs'
NOTE: Name:'LevelInfo' Label:'Variable Level Information' Path:'LevelInfo'
NOTE: Name:'OneWayFreqs' Label:'Eye Color' Path:'Table1.OneWayFreqs'
NOTE: Name:'OneWayFreqs' Label:'Hair Color' Path:'Table2.OneWayFreqs'
NOTE: Name:'CrossList' Label:'Table of Eyes by Hair Controlling for Region=1'
Path:'Table1of3.CrossList'
NOTE: Name:'CrossList' Label:'Table of Eyes by Hair Controlling for Region=2'
Path:'Table2of3.CrossList'
NOTE: Name:'Timing' Label:'Task Timing' Path:'Timing'
You can also use the display parameter to select which tables the freqTab action needs to produce and return to the client. The following code uses the display parameter to select the crosstabulation tables:
action freqTab.freqTab /
table='Color',
weight='Count',
display='CrossList',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}};
run;
In this case, coercion is used to simplify the specification of the display parameter. The uncoerced version of the display specification is display={names={’CrossList’}}. Specifying full paths is optional—the path-matching rules that the display parameter uses are consistent with rules that the ODS SELECT statement uses. The tables that you request by using the display parameter match all tables whose paths end with the specified path. For example, display={names={’CrossList’}} matches all the following paths: Table1of3.CrossList, Table2of3.CrossList, and ByGroup1.Table1.CrossList.
Output 11.1.8 shows the filtered output that contains only the crosstabulation tables.
Output 11.1.8: Filtered Output
| Table of Eyes by Hair Controlling for Region=1 | ||||||
|---|---|---|---|---|---|---|
| Eyes | Hair | Frequency | Total Percent | Percent | Row Percent | Column Percent |
| blue | dark | 11 | 1.44 | 4.47 | 16.92 | 16.92 |
| fair | 23 | 3.02 | 9.35 | 35.38 | 30.26 | |
| medium | 24 | 3.15 | 9.76 | 36.92 | 28.92 | |
| red | 7 | 0.92 | 2.85 | 10.77 | 36.84 | |
| Total | 65 | 8.53 | 26.42 | 100.00 | . | |
| brown | black | 3 | 0.39 | 1.22 | 2.44 | 100.00 |
| dark | 40 | 5.25 | 16.26 | 32.52 | 61.54 | |
| fair | 34 | 4.46 | 13.82 | 27.64 | 44.74 | |
| medium | 41 | 5.38 | 16.67 | 33.33 | 49.40 | |
| red | 5 | 0.66 | 2.03 | 4.07 | 26.32 | |
| Total | 123 | 16.14 | 50.00 | 100.00 | . | |
| green | dark | 14 | 1.84 | 5.69 | 24.14 | 21.54 |
| fair | 19 | 2.49 | 7.72 | 32.76 | 25.00 | |
| medium | 18 | 2.36 | 7.32 | 31.03 | 21.69 | |
| red | 7 | 0.92 | 2.85 | 12.07 | 36.84 | |
| Total | 58 | 7.61 | 23.58 | 100.00 | . | |
| Total | black | 3 | 0.39 | 1.22 | . | 100.00 |
| dark | 65 | 8.53 | 26.42 | . | 100.00 | |
| fair | 76 | 9.97 | 30.89 | . | 100.00 | |
| medium | 83 | 10.89 | 33.74 | . | 100.00 | |
| red | 19 | 2.49 | 7.72 | . | 100.00 | |
| Total | 246 | 32.28 | 100.00 | . | . | |
| Frequency Missing = 10 | ||||||
| Table of Eyes by Hair Controlling for Region=2 | ||||||
|---|---|---|---|---|---|---|
| Eyes | Hair | Frequency | Total Percent | Percent | Row Percent | Column Percent |
| blue | black | 6 | 0.79 | 1.16 | 3.82 | 31.58 |
| dark | 40 | 5.25 | 7.75 | 25.48 | 34.19 | |
| fair | 46 | 6.04 | 8.91 | 29.30 | 30.26 | |
| medium | 44 | 5.77 | 8.53 | 28.03 | 32.84 | |
| red | 21 | 2.76 | 4.07 | 13.38 | 22.34 | |
| Total | 157 | 20.60 | 30.43 | 100.00 | . | |
| brown | black | 13 | 1.71 | 2.52 | 5.96 | 68.42 |
| dark | 54 | 7.09 | 10.47 | 24.77 | 46.15 | |
| fair | 56 | 7.35 | 10.85 | 25.69 | 36.84 | |
| medium | 53 | 6.96 | 10.27 | 24.31 | 39.55 | |
| red | 42 | 5.51 | 8.14 | 19.27 | 44.68 | |
| Total | 218 | 28.61 | 42.25 | 100.00 | . | |
| green | dark | 23 | 3.02 | 4.46 | 16.31 | 19.66 |
| fair | 50 | 6.56 | 9.69 | 35.46 | 32.89 | |
| medium | 37 | 4.86 | 7.17 | 26.24 | 27.61 | |
| red | 31 | 4.07 | 6.01 | 21.99 | 32.98 | |
| Total | 141 | 18.50 | 27.33 | 100.00 | . | |
| Total | black | 19 | 2.49 | 3.68 | . | 100.00 |
| dark | 117 | 15.35 | 22.67 | . | 100.00 | |
| fair | 152 | 19.95 | 29.46 | . | 100.00 | |
| medium | 134 | 17.59 | 25.97 | . | 100.00 | |
| red | 94 | 12.34 | 18.22 | . | 100.00 | |
| Total | 516 | 67.72 | 100.00 | . | . | |
If you enclose the strings in the names subparameter of the display parameter within forward slashes, then those strings are treated as Perl regular expressions that are matched against the full paths of the tables that the action produces. For example, display={names={’/Table1/’}} selects the paths Table1.OneWayFreqs and Table1of3.CrossList.
Using the displayOut (outputTables) Parameter
The freqTab action supports a displayOut (outputTables) parameter, which you can use to save any displayed table as a CAS table in the active caslib. This functionality is analogous to the ODS OUTPUT functionality, which saves ODS output as SAS data sets. The following code provides an example of using this parameter:
action freqTab.freqTab /
table='Color',
weight='Count',
displayOut={names={'NObs', 'OneWayFreqs'}},
tabulate={'Region', 'Eyes', 'Hair'};
run;
Output 11.1.9 displays the "Output CAS Tables," which provide information about all the CAS tables that the action produces. You see that the preceding code created CAS tables named NObs and OneWayFreqs.
Output 11.1.9: Output CAS Tables
| Output CAS Tables | |||
|---|---|---|---|
| CAS Library | Name | Number of Rows | Number of Columns |
| CASUSERHDFS(tiarno) | NObs | 3 | 3 |
| CASUSERHDFS(tiarno) | OneWayFreqs | 10 | 11 |
The following PROC PRINT code displays the OneWayFreqs CAS table on the SAS client by using the CAS engine to bring the table back to the SAS client:
proc print data=mycas.OneWayFreqs;
run;
Output 11.1.10 shows the contents of the OneWayFreqs CAS table.
Output 11.1.10: PROC PRINT of mycas.OneWayFreqs
| Obs | Table | F_Region | Region | Frequency | Percent | CumFrequency | CumPercent | F_Eyes | Eyes | F_Hair | Hair |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | Table1 | 1 | 1 | 256 | 33.1606 | 256 | 33.161 | ||||
| 2 | Table1 | 2 | 2 | 516 | 66.8394 | 772 | 100.000 | ||||
| 3 | Table2 | . | 222 | 28.9063 | 222 | 28.906 | blue | blue | |||
| 4 | Table2 | . | 347 | 45.1823 | 569 | 74.089 | brown | brown | |||
| 5 | Table2 | . | 199 | 25.9115 | 768 | 100.000 | green | green | |||
| 6 | Table3 | . | 22 | 2.8721 | 22 | 2.872 | black | black | |||
| 7 | Table3 | . | 182 | 23.7598 | 204 | 26.632 | dark | dark | |||
| 8 | Table3 | . | 228 | 29.7650 | 432 | 56.397 | fair | fair | |||
| 9 | Table3 | . | 221 | 28.8512 | 653 | 85.248 | medium | medium | |||
| 10 | Table3 | . | 113 | 14.7520 | 766 | 100.000 | red | red |
Notice that the CAS tables that you request in the displayOut parameter consist of all the tables whose paths end with the specified name, and also notice that grouping variables are added to the CAS table so that you can distinguish among the tables. This behavior matches the behavior of ODS OUTPUT. If you want to see a specific table, you can specify the complete path to the table. Furthermore, you can optionally supply your own name for the CAS table that is created, as illustrated in the following code:
proc cas;
action freqTab.freqTab /
table='Color',
weight='Count',
displayOut={names={'Table2.OneWayFreqs'='myTable2'}},
tabulate={'Region', 'Eyes', 'Hair'};
run;
The following PROC PRINT code displays the myTable2 CAS table on the SAS client by using the CAS engine to bring the table back to the SAS client:
proc print data=mycas.myTable2;
run;
Output 11.1.11 shows the second one-way frequency table that is saved in the myTable2 CAS table.
Output 11.1.11: PROC PRINT of mycas.myTable2
| Obs | Table | F_Eyes | Eyes | Frequency | Percent | CumFrequency | CumPercent |
|---|---|---|---|---|---|---|---|
| 1 | Table2 | blue | blue | 222 | 28.9063 | 222 | 28.906 |
| 2 | Table2 | brown | brown | 347 | 45.1823 | 569 | 74.089 |
| 3 | Table2 | green | green | 199 | 25.9115 | 768 | 100.000 |
BY Processing
You can use the groupBy subparameter of the table parameter to specify BY processing in the freqTab action. Unlike BY processing in SAS procedures, BY processing in the freqTab action does not require the input table to be sorted by the variable or variables that you name in the groupBy subparameter. In the preceding code snippets in this example, the table parameter is specified simply as table=’Color’. This form is the coerced simplification of the general specification of the table parameter when only the name subparameter is needed. You can use a partially coerced form to specify BY processing with a single BY variable, as shown in the following code:
proc cas;
action freqTab.freqTab /
table={name='Color', groupBy='Region'},
weight='Count',
display={names={'NObs', 'OneWayFreqs'}, traceNames=true},
tabulate={'Eyes', 'Hair'};
run;
Output 11.1.12 shows the output. You see that the output of the BY group is identified by a title that contains the name and value of the BY variable.
Output 11.1.12: BY Processing Output
| Number of Observations Read | 16 |
|---|---|
| Number of Observations Used | 15 |
| Sum of Weights | 256 |
| Eye Color | ||||
|---|---|---|---|---|
| Eyes | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| blue | 65 | 25.79 | 65 | 25.79 |
| brown | 129 | 51.19 | 194 | 76.98 |
| green | 58 | 23.02 | 252 | 100.00 |
| Frequency Missing = 4 | ||||
| Hair Color | ||||
|---|---|---|---|---|
| Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| black | 3 | 1.20 | 3 | 1.20 |
| dark | 65 | 26.00 | 68 | 27.20 |
| fair | 76 | 30.40 | 144 | 57.60 |
| medium | 87 | 34.80 | 231 | 92.40 |
| red | 19 | 7.60 | 250 | 100.00 |
| Frequency Missing = 6 | ||||
| Number of Observations Read | 14 |
|---|---|
| Number of Observations Used | 14 |
| Sum of Weights | 516 |
| Eye Color | ||||
|---|---|---|---|---|
| Eyes | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| blue | 157 | 30.43 | 157 | 30.43 |
| brown | 218 | 42.25 | 375 | 72.67 |
| green | 141 | 27.33 | 516 | 100.00 |
| Hair Color | ||||
|---|---|---|---|---|
| Hair | Frequency | Percent | Cumulative Frequency | Cumulative Percent |
| black | 19 | 3.68 | 19 | 3.68 |
| dark | 117 | 22.67 | 136 | 26.36 |
| fair | 152 | 29.46 | 288 | 55.81 |
| medium | 134 | 25.97 | 422 | 81.78 |
| red | 94 | 18.22 | 516 | 100.00 |
Furthermore, the following notes in the SAS log (which you request by specifying the traceNames subparameter in the display parameter) show that the table paths contain a prefix that identifies the BY-group index:
NOTE: Name:'NObs' Label:'Number of Observations' Path:'ByGroup1.NObs' NOTE: Name:'OneWayFreqs' Label:'Eye Color' Path:'ByGroup1.Table1.OneWayFreqs' NOTE: Name:'OneWayFreqs' Label:'Hair Color' Path:'ByGroup1.Table2.OneWayFreqs' NOTE: Name:'NObs' Label:'Number of Observations' Path:'ByGroup2.NObs' NOTE: Name:'OneWayFreqs' Label:'Eye Color' Path:'ByGroup2.Table1.OneWayFreqs' NOTE: Name:'OneWayFreqs' Label:'Hair Color' Path:'ByGroup2.Table2.OneWayFreqs'
Saving the Results of an Action Submission
In the previous examples, the output of the freqTab action is immediately displayed. If you route the results to a named result, then the output is saved in the named result and is not displayed. The following code shows how you can do this:
action freqTab.freqTab result=myResult /
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}};
run;
After you run the preceding code, the results of running the freqTab action are stored in the variable named myResult, but no output is displayed. You can display the tables that are stored in myResult by using the PRINT statement in PROC CAS as follows:
print myResult;
run;
The output of running this PRINT statement is the same as when you run the freqTab action without assigning the results; it is not produced here. You can also display specific tables that are stored in myResult. The following code shows how you can print the crosstabulation tables:
print myResult['Table1of3.CrossList']
myResult['Table2of3.CrossList'];
run;
The requested output is not reproduced here but is shown in Output 11.1.8.
For every one-way frequency or crosstabulation table that the freqTab action produces, it saves the frequency of observations that have missing values in the attributes of the result table. The following code shows how you can display the frequency of observations that have missing values for specific one-way frequency or crosstabulation tables:
print myResult['Table1.OneWayFreqs'].attrs['Frequency Missing']
myResult['Table2.OneWayFreqs'].attrs['Frequency Missing']
myResult['Table1of3.CrossList'].attrs['Frequency Missing']
myResult['Table2of3.CrossList'].attrs['Frequency Missing'];
run;
To be able to use the PRINT statement to print specific tables in a stored result, you need to know the paths of those tables in the stored result. One way to get this information is to specify display={traceNames=true} in the freqTab action and obtain the paths of the tables that it produces. Another way to get the paths is to use the DESCRIBE statement in PROC CAS as follows:
describe myResult;
run;
This displays in the SAS log a dictionary of the tables and the columns in those tables that are stored in myResult. A subset of this dictionary for the "LevelInfo" and "CrossList" tables follows:
dictionary ( 7 entries, 7 used);
[LevelInfo] Table ( [3] Rows [4] columns
Column Names:
[1] Variable [Variable ] (string)
[2] Label [Label ] (string)
[3] Levels [Levels ] (double)
[4] Values [Values ] (string)
[Table1of3.CrossList] Table[CrossList] ( [22] Rows [9] columns
Column Names:
[1] F_Eyes [Eyes ] (string)
[2] Eyes [Eye Color ] (string)
[3] F_Hair [Hair ] (string)
[4] Hair [Hair Color ] (string)
[5] Frequency [Frequency Count ] (double)
[6] TotalPercent [Percent of Total Frequency] (double)
[7] Percent [Percent of Two-Way Table Frequency] (double)
[8] RowPercent [Percent of Row Frequency] (double)
[9] ColPercent [Percent of Column Frequency] (double)
This dictionary contains the paths (such as Table1of3.CrossList) of all tables in myResult. You must use the complete path to request specific tables in the PRINT statement.
Saving the Status of an Action Submission
The status of each action submission is available in the _status variable, which contains several fields that you can access programmatically. You can display the contents of _status by using the PRINT statement as follows:
print _status;
run;
For an action that runs without error, this PRINT statement displays the following line in the SAS log:
{severity=0,reason=0,,statusCode=0}
You can access and print individual fields in the status by using dot notation as follows:
print _status.severity;
run;
This PRINT statement displays the number 0 (the contents of _status.severity) in the SAS log.
The following code submits the freqTab action but specifies a weight variable that does not exist in the input table (which is an error). It also illustrates how you can assign the status of the action to a variable that you name.
action freqTab.freqTab status=myStatus /
table='Color',
weight='TotalCount',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}};
run;
print myStatus;
run;
This code produces the following errors in the SAS log:
ERROR: The variable TotalCount does not exist in table COLOR. ERROR: The action stopped due to errors.
The nature of the error is also saved in the status variable myStatus, which you can display as follows:
print myStatus;
run;
This PRINT statement produces the following line in the SAS log:
{severity=2,reason=6,status=
The variable TotalCount does not exist in table COLOR.,statusCode=5890022}
For more information about severity and reason codes, see the section "Programming with Severity and Reason Codes" in SAS Viya: System Programming Guide.
Frequency Tables
This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the Color data to the comma-separated-value (CSV) file Color.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="Color.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The Lua code highlights sections of the CASL example where the Lua syntax differs significantly from the CASL syntax. See the CASL version of this example for discussions of the data, syntax features, and the output of running these examples.
Loading the freqTab Action Set and Running the freqTab Action
You can specify an action by using the action set name and the action name separated by an underscore (actionset_action). For example, you can specify the name freqTab_freqTab to run the freqTab action in the freqTab action set as shown in the following code:
s:freqTab_freqTab{
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}}
}
When you use the actionset_action form of specifying the action, the action set is loaded automatically into your CAS session if it is not already loaded. The following code shows how you can explicitly load the freqTab action set:
s:loadactionset{actionset='freqTab'}
After the freqTab action set is loaded, you can run the freqTab action without also having to name the freqTab action set, as shown in the following code:
s:freqTab{
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}}
}
Saving the Results of an Action Submission
As in the CASL case, you can submit actions from Lua without specifying a named result, as shown in the following code:
s:freqTab{
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}}
}
When you submit the preceding code, the results are sent to the Lua client and displayed immediately as the action runs. If you want to save the results, you can name the results as shown in the following code:
myResult=s:freqTab{
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}}
}
In this case, the results are not displayed but are stored in a variable named myResult. You can display the contents of the myResult variable by entering myResult at the Lua prompt. This displays all the tables that are produced by this action call along with their full pathnames. You can specify table pathnames in a print command to display specific tables, as shown in the following code:
print(myResult.NObs)
print(myResult.LevelInfo)
print(myResult["Table1.OneWayFreqs"])
print(myResult["Table2.OneWayFreqs"])
print(myResult["Table1of3.CrossList"])
print(myResult["Table2of3.CrossList"])
For every one-way frequency or crosstabulation table that the freqTab action produces, it saves the frequency of observations that have missing values in the attributes of the result table. The following code shows how you can display the frequency of observations that have missing values for specific one-way frequency or crosstabulation tables:
print(myResult["Table1.OneWayFreqs"].attrs["Frequency Missing"])
print(myResult["Table2.OneWayFreqs"].attrs["Frequency Missing"])
print(myResult["Table1of3.CrossList"].attrs["Frequency Missing"])
print(myResult["Table2of3.CrossList"].attrs["Frequency Missing"])
Saving the Status of an Action Submission
The following code shows how you can save the status of an action call by providing a name for the status variable after you specify a name for the results:
myResult, myStatus=s:freqTab{
table='Color',
weight='Count',
tabulate={'Eyes', 'Hair', {vars={'Region', 'Eyes', 'Hair'}}}
}
The preceding code saves the status of the action submission in the variable myStatus. You can display the contents of the myStatus variable by entering myStatus at the Lua prompt.
For more information about severity and reason codes, see the section "Programming with Severity and Reason Codes" in SAS Viya: System Programming Guide.
Full-Featured Examples
The code that follows shows many features of the freqTab action, including the following:
subsetting results by using the
displayparameter with Perl regular expressionsobtaining paths of the results tables by using the
traceNamessubparameter of thedisplayparametersaving specified results as CAS tables by using the
displayOutparameterspecifying formats and labels for variables by using the
attributesparameterrequesting the frequency and crosstabulation tables to produce by using the
tabulateparameterdisplaying crosstabulation tables in CROSSLIST format by default
myResult, myStatus=s:freqTab{
table='Color',
weight='Count',
attributes={{name='Region', format='roman4.', label='European Region'}
},
display={names='/Table/',
traceNames=true
},
displayOut={names={NObs='myNObs',
LevelInfo='myLevelInfo',
OneWayFreqs='myOneWayFreqs',
CrossList='myCrossList'
}
},
tabulate={'Eyes', 'Hair',
{vars={'Eyes', 'Hair'}},
{vars={'Region', 'Eyes', 'Hair'}},
{vars='Region', cross={'Eyes', 'Hair'}}
}
}
The code that follows shows additional features of the freqTab action, including the following:
processing groups by using the
groupBysubparameter of thetableparameterdisplaying crosstabulation tables in LIST format by using the
formatsubparameter of thetabDisplayparameterdisplaying missing levels in one-way tables or crosstabulation tables in LIST format by using the
missingFreqsubparameter of thetabDisplayparameter
myResult, myStatus=s:freqTab{
table={name='Color', groupBy='Region'},
weight='Count',
attributes={{name='Region', format='roman4.', label='European Region'}
},
display={names={'NObs', 'LevelInfo', '/Table/'},
traceNames=true
},
displayOut={names={'NObs', 'LevelInfo', 'OneWayFreqs', 'List'}
},
tabDisplay={format='LIST', missingFreq=true},
tabulate={'Eyes', 'Hair',
{vars={'Eyes', 'Hair'}}
}
}
For explanations and output of features highlighted in this section, see the CASL example.
Frequency Tables
This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.
Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the Color data to the comma-separated-value (CSV) file Color.csv and then use the following code to load the CSV file into CAS:
s.upload_file('Color.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The Python code highlights sections of the CASL example where the Python syntax differs significantly from the CASL syntax. See the CASL version of this example for discussions of the data, syntax features, and the output of running these examples.
Loading the freqTab Action Set and Running the freqTab Action
The following code loads the freqTab action set:
s.loadactionset(actionset='freqTab')
You can specify an action by using the action set name and the action name separated by a dot (actionset.action). For example, you can use the name freqTab.freqTab to run the freqTab action in the freqTab action set, as shown in the following code:
s.freqTab.freqTab(
table='Color',
weight='Count',
tabulate=['Eyes', 'Hair', {'vars':['Region', 'Eyes', 'Hair']}]
)
The following code shows that you do not have to specify the action set name when you run the freqTab action:
s.freqTab(
table='Color',
weight='Count',
tabulate=['Eyes', 'Hair', {'vars':['Region', 'Eyes', 'Hair']}]
)
Saving the Results of an Action Submission
As in the CASL case, you can submit actions from Python without specifying a named result, as shown in the following code:
s.freqTab(
table='Color',
weight='Count',
tabulate=['Eyes', 'Hair', {'vars':['Region', 'Eyes', 'Hair']}]
)
When you submit the preceding code, the results are sent to the Python client and displayed immediately as the action runs. If you want to save the results, you can name the results as shown in the following code:
myResult=s.freqTab(
table='Color',
weight='Count',
tabulate=['Eyes', 'Hair', {'vars':['Region', 'Eyes', 'Hair']}]
)
In this case, the results are not displayed but are stored in a variable named myResult. The following command displays all the tables that are produced by this action call along with their full pathnames:
print(myResult)
The following commands individually display the tables that are produced by this action call:
print(myResult.NObs)
print(myResult.LevelInfo)
print(myResult["Table1.OneWayFreqs"])
print(myResult["Table2.OneWayFreqs"])
print(myResult["Table1of3.CrossList"])
print(myResult["Table2of3.CrossList"])
For every one-way frequency or crosstabulation table that the freqTab action produces, it saves the frequency of observations that have missing values in the attributes of the result table. The following code shows how you can display the frequency of observations that have missing values for specific one-way frequency or crosstabulation tables:
print(myResult["Table1.OneWayFreqs"].attrs["Frequency Missing"])
print(myResult["Table2.OneWayFreqs"].attrs["Frequency Missing"])
print(myResult["Table1of3.CrossList"].attrs["Frequency Missing"])
print(myResult["Table2of3.CrossList"].attrs["Frequency Missing"])
Status information about the action submission is also saved in myResult. You can display the severity, reason, and status fields by using the print command as follows:
print("Severity code:", myResult.severity)
print("Reason: ", myResult.reason)
print("Status: ", myResult.status)
For more information about severity and reason codes, see the section "Programming with Severity and Reason Codes" in SAS Viya: System Programming Guide.
Full-Featured Examples
The code that follows shows many features of the freqTab action, including the following:
subsetting results by using the
displayparameter with Perl regular expressionsobtaining paths of the results tables by using the
traceNamessubparameter of thedisplayparametersaving specified results as CAS tables by using the
displayOutparameterspecifying formats and labels for variables by using the
attributesparameterrequesting the frequency and crosstabulation tables to produce by using the
tabulateparameterdisplaying crosstabulation tables in CROSSLIST format by default
myResult=s.freqTab(
table='Color',
weight='Count',
attributes=[{'name':'Region', 'format':'roman4.', 'label':'European Region'}
],
display={'names':['/Table/'],
'traceNames':'true'
},
displayOut={'names':{'NObs':'myNObs',
'LevelInfo':'myLevelInfo',
'OneWayFreqs':'myOneWayFreqs',
'CrossList':'myCrossList'}
},
tabulate=['Eyes', 'Hair',
{'vars':['Eyes', 'Hair']},
{'vars':['Region', 'Eyes', 'Hair']},
{'vars':'Region', 'cross':['Eyes', 'Hair']}
]
)
The code that follows shows additional features of the freqTab action, including the following:
processing groups by using the
groupBysubparameter of thetableparameterdisplaying crosstabulation tables in LIST format by using the
formatsubparameter of thetabDisplayparameterdisplaying missing levels in one-way tables or crosstabulation tables in LIST format by using the
missingFreqsubparameter of thetabDisplayparameter
myResult=s.freqTab(
table={'name':'Color', 'groupBy':'Region'},
weight='Count',
attributes=[{'name':'Region', 'format':'roman4.', 'label':'European Region'}
],
display={'names':['NObs', 'LevelInfo', '/Table/'],
'traceNames':'true'
},
displayOut={'names':['NObs', 'LevelInfo', 'OneWayFreqs', 'List']
},
tabDisplay={'format':'LIST', 'missingFreq':'true'},
tabulate=['Eyes', 'Hair',
{'vars':['Eyes', 'Hair']}
]
)
For explanations and output of features highlighted in this section, see the CASL example.
Frequency Tables
This example is not available for the R programming language.