The data comes from the 'classurv15' dataset, accessible via the 'class' library which is mapped to an external file system path specified by a LIBNAME statement.
1 Code Block
Configuration
Explanation : This block configures the SAS environment by creating the 'class' libname which points to a folder containing the data. The 'fmtsearch' option tells SAS where to search for custom formats, especially in the 'class' library.
Copied!
libname class "Z:\Dropbox\UNTHSC Admin and Teaching\Courses\5147-Fall 2014\BACH_EPID 5313\Data\Day one survey\5147\";
options fmtsearch = (class);
1
LIBNAME class "Z:\Dropbox\UNTHSC Admin and Teaching\Courses\5147-Fall 2014\BACH_EPID 5313\
2
DATA\Day one survey\5147\";
3
options fmtsearch = (class);
4
2 Code Block
PROC FREQ
Explanation : This procedure generates an initial cross-frequency table for the 'persdoc' and 'genhealth' variables from the 'class.classurv15' dataset, without applying specific formats, to display the original distributions.
Copied!
/*
Revisit the persdoc by genhealth frequency table.
*/
proc freq data=class.classurv15;
tables persdoc*genhealth;
run;
1
/*
2
Revisit the persdoc by genhealth frequency table.
3
*/
4
PROC FREQDATA=class.classurv15;
5
tables persdoc*genhealth;
6
RUN;
3 Code Block
PROC FORMAT
Explanation : This block uses 'PROC FORMAT' to define two custom formats: 'fpersdoc' and 'fgenhealth'. These formats group the original categories of the 'persdoc' and 'genhealth' variables into broader groups, thus simplifying the analysis and the creation of a 2x2 table.
Copied!
/*
Using formats to collapse categories of persdoc and genhealth in order to create a two-by-two
table
*/
proc format;
value fpersdoc 0 = "No Personal Doctor"
1-2 = "At Least One Personal Doctor";
value fgenhealth 1-2 = "Excellent, Very Good, or Good"
3-high = "Fair or Poor";
run;
1
/*
2
Using formats to collapse categories of persdoc and genhealth in order to create a two-by-two
3
table
4
*/
5
PROC FORMAT;
6
value fpersdoc 0 = "No Personal Doctor"
7
1-2 = "At Least One Personal Doctor";
8
value fgenhealth 1-2 = "Excellent, Very Good, or Good"
9
3-high = "Fair or Poor";
10
RUN;
4 Code Block
PROC FREQ
Explanation : This 'PROC FREQ' procedure generates a cross-frequency table for 'persdoc' and 'genhealth', but this time, it applies the custom formats 'fpersdoc' and 'fgenhealth'. This allows visualizing the distribution of variables with grouped categories.
Explanation : This final 'PROC FREQ' block performs a Chi-square test on the formatted cross-frequency table. The 'chisq' option requests the calculation of the Chi-square statistic, 'expected' displays the expected counts under the assumption of independence, and 'nocol' suppresses the display of column percentages for an output more focused on the test.
Copied!
/*
Chi-square test for the difference between distributions
*/
proc freq data=class.classurv15;
tables persdoc*genhealth / chisq expected nocol;
format persdoc fpersdoc. genhealth fgenhealth.;
run;
1
/*
2
Chi-square test for the difference between distributions
3
*/
4
PROC FREQDATA=class.classurv15;
5
tables persdoc*genhealth / chisq expected nocol;
6
FORMAT persdoc fpersdoc. genhealth fgenhealth.;
7
RUN;
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.