/*---------------------------------------------------------------- ex4.sas Code to run exemplar 4 Written by Gillian Raab November 2004 first tell sas where the data for this exemplar is stored Change this to the directory where YOU have the data -----------------------------------------------------------------*/ libname exemp4 "c:/documents and settings/gillian raab/my documents/aprojects/peas/ex4datafiles/data"; /*------------------------------------------------- Now you should open the file ex4_formats.sas and run it to set up the formats you will need for these analyses Check log file to see that it has worked ----------------------------------------------------*/ ods html file="c:/documents and settings/gillian raab/my documents/aprojects/peas/ex4datafiles/results/sasoutput.htm"; /*-------------------------------------------------------------- first weighted and unweighted means of proportion with eo policy Table 4.3 --------------------------------------------------------------*/ proc surveymeans data=exemp4.ex4 mean stderr nobs clm; var eo; strata strata; weight est_wt; run; proc surveymeans data=exemp4.ex4 mean stderr nobs clm; weight est_wt; var eo; strata strata; run; /*------------------- without startification----------------------*/ proc surveymeans data=exemp4.ex4 mean stderr nobs clm; var eo; weight est_wt; run; /*-----now eo by workplace size-----table4.4--------------*/ proc surveymeans data=exemp4.ex4 mean stderr nobs clm; weight est_wt; var eo; strata strata; domain nempsize; run; /*---------------------------------------------------------------------- now compare means and proportions by eo and non eo workplaces table 4.5 --------------------------------------------------------------------*/ proc surveymeans data=exemp4.ex4 mean stderr nobs clm; weight est_wt; var female ethnic disabgrp; class disabgrp; format disabgrp disabgrp.; strata strata; domain eo; run; /*------------------- and the same thing unweighted-----------------*/ proc surveymeans data=exemp4.ex4 mean stderr nobs clm; var female ethnic disabgrp; class disabgrp; format disabgrp disabgrp.; strata strata; domain eo; run; /*--------------------------------------------------------- to get a t-test you need to use the regresion procedure ---------------------------------------------------*/ proc surveyreg data=exemp4.ex4; weight est_wt; strata strata; model female=eo ; ods select ParameterEstimates; run; proc surveyreg data=exemp4.ex4; weight est_wt; strata strata; model ethnic=eo ; ods select ParameterEstimates; run; /*------------------------------------------------------ and they can be compared with an ordinary t-test ------------------------------------------------------*/ proc ttest data=exemp4.ex4; var female ethnic; class eo; run; /*------------------------------------------------------- SAS version 8 does not do logistic regression, but with a sample this size oridinary regression will be OK though obviously not exactly the same as the logistic regressions Version 9 will -----------------------------------------------------------------------*/ /*------------------------------------------------------------ now testing the effect of a finite population correction For this we need to make a SAS table with a record for each startum and a variable _rate_ with the sampling fraction table 4.8 -----------------------------------------====---------------*/ proc sort data=exemp4.ex4 out=rates; by strata; run; data rates; set rates; by strata; if first.strata; _rate_=sampfrac; keep _rate_ strata; run; proc surveymeans data=exemp4.ex4 mean stderr nobs clm rate=rates; weight est_wt; var eo; strata strata; domain nempsize; run;