Html Version of SAS Code to run exemplar 2
It is intended to show you the code and to allow links, not to use 
as a SAS program. The SAS program is the file ex2.sas which you should
save to a file and/or read in to SAS.
To see output from the commands go to the SAS results file.

Links in this page Simple means and proportions Table 2.3
Effect of design aspects on precision of estimates table 2.4
Tables 2.6 onwards
EVERYTHING INSIDE /* AND */ IS TAKEN AS A COMMENT in SAS programs These are shown in green here
-------------------------------------------------------------------*/ /*----------------------------------------------------------------- Written by Gillian Raab August 2004 first tell sas where the data forthis exemplar is stored Change this to the directory where YOU have the data ---------------------------------------------------------------------------------*/ libname exemp2 "G:\peas\ex2datafiles\data"; /*-------------------------------------------------------------------------------- exemplar first for simple proportions of internet use and other results in Table 2.3 INTUSE is a 0/1 variable so its mean gives the percentage use The declaration of the survey design is done withing the survey procedures in SAS --------------------------------------------------------------------------------*/ back to top uparrow title 'Simple proportioninternet use'; options 'nocenter'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; * no strata; weight ind_wt; cluster psu; var intuse; strata stratum; run; /*------------------------------------------------------- we can also get proportions in groups that have several categories by defining the variable as a class variable IMPORTANT IMPORTANTIMPORTANT !!!!!!!!!!!!!????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Before this you should open and run the SAS programme ex2_formats.sas This provides formats s to use as value labels for your variables This gives proportions of internet users who use the internet for different numbers of hours per day -----------------------------------------------------------------------*/ title 'Hours of internet use for users'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; weight ind_wt; cluster psu; strata stratum; var rc5;������* say which variable(s)you want; classrc5;������������� * and define it as a class (category); format rc5 hours.;������ * with format defined as hours. See ex2_formats.sas; run; /*------------------------------------------------------------------------- We can get proportions in subgroupsfor simple means by using the DOMAIN statement THIS is AVAILABLE in SAS 8.2 only and is not in the SAS online help yet Here we look at usage by sex --------------------------------------------------------------------------------*/ title 'internet use by sex'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; weight ind_wt; cluster psu; strata stratum; var intuse; domain sex; format sex sex.; run; title 'hours used by sex'; /*--------------------------------------------------------------------------------- and we can similarly look at the proportions of men and women internet users who use the internet for different times each day ----------------------------------------------------------------------------------*/ proc surveymeans data=exemp2.ex2 mean stderr nobs clm; weight ind_wt; cluster psu; strata stratum; var rc5; class rc5; domain sex; format sex sex.; run; /*------------------------------------------------- Now looking at the effect of different designs on the precision of estimates for results as in Table 2.4 ----------------------------------------------------*/ back to top uparrow title 'clustering no stratification'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; cluster psu; weight ind_wt; var intuse; run; title ' stratification no clustering'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; weight ind_wt; strata stratum; var intuse; run; title 'no stratification or clustering'; proc surveymeans data=exemp2.ex2 mean stderr nobs clm; * no weight ind_wt; var intuse; run; /*------------------------------------------------------ NOW ANALYSES BY FOR TABLES first do PROC freq to get a table of weighted percentages !!!!!!!!!!!!!!!!! IMPORTANT IMPORTANTIMPORTANT !!!!!!!!!!!!!????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Before this you should open and run the SAS programme ex2_formats.sas This puts value labels on your variables --------------------------------------------------------*/ title 'tables with wrong chi square results'; proc freq data=exemp2.ex2; table intuse*sex/nopercent nocol chisq; weight ind_wt; format rc5 hours. emp_sta employ.; run; /*-------------------------------------------------------- this has given you a table of weighted percentages that are the correct estimates of the percentages using internet by sex. It also gives a chi squared value, but it makes no allowance for the sample design and so is not correct ------------------------------------------------------------*/ /*-------------------------------------------------------- same is true for all other tables -here is a larger one ------------------------------------------------------------*/ proc freq data=exemp2.ex2; table shs_6cla*rc5/nopercent nocol chisq missing; weight ind_wt; format rc5 hours. shs_6cla rural.; run; /*-------------------------------------------------------- Now use PROC tabulate to get a nice layout for a weighted Table with row percentagesand the base numbers shown in the final column ------------------------------------------------------------*/ title 'nice table layout'; proc tabulate data=exemp2.ex2 missing; var ind_wt; class rc5shs_6cla; formatrc5 hours. shs_6cla rural.; ; table�� shs_6cla='', (rc5 all)*ind_wt=''*pctsum<rc5 all>*f=4.1 n='base'*f=5.0; run; /*---------------------------------------------------------- sas does not do chi square tests for tables or logistic regression for surveys ----------------------------------------------------------------*/