Published on :
Statistical CREATION_INTERNE

Documentation Example 5 for ODS

This code is also available in: Deutsch Español Français
Awaiting validation
The script creates a 'Color' dataset containing eye and hair color data. It then uses ODS (Output Delivery System) to redirect statistical results (Chi-Square and Likelihood Ratio Chi-Square) calculated by PROC FREQ directly into a SAS© table named 'myStats', while suppressing display in the results window via 'ods select none'.
Data Analysis

Type : CREATION_INTERNE


Data is included in the script via the DATALINES statement.

1 Code Block
DATA STEP Data
Explanation :
Creation of the 'Color' table from internal data. The '@@' operator allows reading multiple observations on the same data line.
Copied!
1title 'Hair Color of European Children';
2 
3DATA Color;
4 INPUT Region Eyes $ Hair $ Count @code_sas_json/8_SAS_Intro_ReadFile_MultiCol_@@.json;
5 label Eyes ='Eye Color'
6 Hair ='Hair Color'
7 Region='Geographic Region';
8 DATALINES;
91 blue fair 23 1 blue red 7 1 blue medium 24
101 blue dark 11 1 green fair 19 1 green red 7
111 green medium 18 1 green dark 14 1 brown fair 34
121 brown red 5 1 brown medium 41 1 brown dark 40
131 brown black 3 2 blue fair 46 2 blue red 21
142 blue medium 44 2 blue dark 40 2 blue black 6
152 green fair 50 2 green red 31 2 green medium 37
162 green dark 23 2 brown fair 56 2 brown red 42
172 brown medium 53 2 brown dark 54 2 brown black 13
18;
2 Code Block
PROC SORT
Explanation :
Sorting data by the 'Region' variable. The 'ods select none' statement disables sending output to active ODS destinations (like the Results window) to avoid displaying unnecessary reports for sorting.
Copied!
1ods select none;
2 
3PROC SORT DATA=Color;
4 BY Region;
5RUN;
3 Code Block
PROC FREQ Data
Explanation :
Calculation of frequencies and statistical tests. 'ods output ChiSq=myStats' captures the ODS 'ChiSq' table generated by PROC FREQ and stores it in the SAS table 'myStats'. Dataset options filter to keep only statistics starting with 'Chi' or 'Like'.
Copied!
1ods OUTPUT ChiSq=myStats(drop=TABLE
2 where=(Statistic =: 'Chi' or
3 Statistic =: 'Like'));
4 
5PROC FREQ DATA=Color order=DATA;
6 weight Count;
7 tables Eyes*Hair / testp=(30 12 30 25 3);
8 BY Region;
9RUN;
4 Code Block
PROC PRINT
Explanation :
Reactivation of ODS display ('ods select all') and display of the content of the 'myStats' output table containing the captured statistical results.
Copied!
1ods select all;
2PROC PRINT
3DATA=myStats noobs;
4RUN;
5 
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.