/*----------------------------------------------------------------

ex3.sas Code to run exemplar 3

Written by Gillian Raab

October 2004

 

first tell sas where the data for this exemplar is stored

Change this to the directory where YOU have the data

-----------------------------------------------------------------*/

libname exemp3 'c:\documents and settings\gillian raab\my documents\aprojects\peas\web\exemp3\data\' ;

/*-------------------------------------------------

NOW open and run the program

ex3_formats.sas

YOU WILL NEED THIS FOR THE NEXT BITS TO RUN CORRECTLY

Now use surveymeans to get standard errrors of proportions

of different smoking categories

NOTICE THAT THE CLASS STATEMENT TELLS SAS TO DO PROPORTIONS

----------------------------------------------------*/

title 'PROPORTION SMOKING';

proc surveymeans data=exemp3.ex3 mean stderr nobs clm; * no strata;

weight WEIGHTA;

cluster psu;

CLASS CIGST1 ;

FORMAT CIGST1 CIGSTA.;

var CIGST1;

strata stratum;

run;

/*-------------------------------------------------------

nOW RECODE THIS TO GET A VARIABLE FOR SMOKERS

-----------------------------------------------------------------------*/

DATA EX3; * NOTE THIS IS TEMP FILE ;

SET EXEMP3.EX3;

if cigst1=4 then smoker=1;

else if cigst1=. then smoker=.;

else smoker=0;

if nofad>5 then nofad=5; * recode all large adults >5 to 5;

run;

title 'Proportion smoking by number of adults';

proc surveymeans data=ex3 mean stderr nobs clm; * smoking by number of adults;

weight WEIGHTA;

cluster psu;

CLASS smoker ;

domain nofad;

var smoker;

strata stratum;

run;

title 'Proportion smoking by sex';

proc surveymeans data=ex3 mean stderr nobs clm; * now by sex;

weight WEIGHTA;

cluster psu;

CLASS smoker ;

domain sex;

format sex sex.;

var smoker;

strata stratum;

run;

/*---------------------------------------------------------------

to compare smoking rates by groups need to use regression

--------------------------------------------------------------*/

proc surveyreg data=ex3;

weight WEIGHTA; cluster psu;strata stratum;

model smoker=sex;

format sex sex.;

run;

title 'Proportion smoking by health board';

proc surveymeans data=ex3 mean stderr nobs clm; * now by health board;

weight WEIGHTA;

cluster psu;

CLASS smoker ;

domain hboard;

format hboard hboard.;

var smoker;

strata stratum;

run;

proc surveyreg data=ex3 ; * now a complicated model;

weight WEIGHTA;cluster psu;strata stratum;

CLASS hboard ;

format hboard hboardn.;

model smoker= hboard /solution;

estimate 'fife - lothian' hboard 0 0 0 0 1 0 0 0 0 0 0 -1 0 0 0;

run;

title 'Proportion smoking more complicated model';

proc surveyreg data=ex3 ; * now a complicated model;

weight WEIGHTA;cluster psu;strata stratum;

CLASS age sex hboard ;

format sex sex. age age. hboard hboardn.;

model smoker=nofad age sex hboard age*sex nofad*sex nofad*age ;

run;

title 'Proportion smoking final model';

proc surveyreg data=ex3 ; * now a complicated model;

weight WEIGHTA;cluster psu;strata stratum;

CLASS age sex hboard ;

format sex sex. age age. hboard hboardn.;

model smoker=nofad age sex hboard /solution ; * this gives estimates;

run;