*Call in PAT Wave1 Wave 2. Working data set is called pat_w1w2	*
*This program provides sample code to use when analyzing survey data	*
*There are 3811 observations and 190 variables in the dataset	*

The stratification (nesting) variable is strata_pat
The survey weight variable is wt_patw1w2

For more information, please contact:
NYC Department of Health & Mental Hygiene
Bureau of Epidemiology Services
EpiDatarequest@health.nyc.gov
*********************************************************************;

/*enter in the pathway where dataset is stored*/

libname PAT 'X';

/* format statements and instructions below */
proc format;
value yesnona
1='Yes'
2='No'
.n ='Not asked'
.d= "Don't know";

value yesno
1='Yes'
2='No'
.d="Don't know";

/*Mobility Screen*/
value mobility2f
1="Permanent"
2="Temporary"
.d= "Don't know";

value mobility1typef
1="Able to walk > 10'"
2="Temp unable to walk >10'"
3="Perm unable to walk >10'"
.d= "Don't know";

/*DEMOGRAPHICS*/
value agegrp
1='18-24'
2='25-44'
3='45-64'
4='65+'
.d= "Don't know";

value age1864f
1='18-24'
2='25-44'
3='45-64'
.d= "Don't know";

value sex
1='Male'
2='Female';

value race
1='White, non-Hispanic'
2='Black, non-Hispanic'
3='Hispanic'
4='Asian/PI, non-Hispanic'
5='Other, non-Hispanic';

value dem8f
1='USA'
2='Outside USA'
.d="Don't know"
.r="Refused";

value dem9yrs
1='Less than 10 yrs'
2='10 - 19 yrs'
3='20 - 29 yrs'
4='30+ yrs'
.r="Refused"
.n="Not asked"
.d="Don't know";

value dem10f
1='English'
2='Spanish'
3='Russian'
4='Chinese'
6='Other'
.r="Refused"
.d="Don't know";

value dem11f
1='Married'
2='Divorced'
3='Widowed'
4='Separated'
5='Never married'
6='Unmarried couple living together'
.r="Refused"
.d="Don't know";

value dem12f
1='Never attended/ only kindergarten'
2='Grades 1 to 8 (elementary)'
3='Grade 9 to 11 (some high school)'
4='Grade 12 or GED (high school grad)'
5='College 1 to 3 yrs (some college)'
6='College 4 yrs (college grad)'
7='Graduate or prof degree'
.r="Refused"
.d="Don't know";

value educ
1='Less than high school'
2='High school grad'
3='Some college'
4='College grad or higher'
.r="Refused"
.d="Don't know";

value dem14f
1='Employed for wages'
2='Self-employed'
3='Homemaker'
4='Student'
5='Retired'
6='Unable to work'
7='Unemployed for 1 yr or more'
8='Unemployed <1yr'
.d="Don't know";

value emp3f
1='Employed'
2='Unemployed'
3='Not in labor force'
.r="Refused"
.d="Don't know";

value pov6f
1='<100% '
2='100-199%'
3='200-399%'
4='400-599%'
5='600% +'
6="Don't know"
.r="Refused"
.d="Don't know";

value pov200f
1='<200%'
2='200% +'
3="Don't know"
.r="Refused"
.d="Don't know";

value pov3f
1='<200%'
2='200-399%'
3='400% +'
4="Don't know"
.r="Refused"
.d="Don't know";

value hh3f
1='One'
2='Two'
3='Three or more';

/*TRANSPORTATION AND COMMUTING*/
value transport1f
1='Work outside home'
2='Work from home'
.n ='Not asked'
.r="Refused"
.d="Don't know";

value transport2f
1='Weekdays'
2='Weekends'
3='Both weekdays/ends'
.n='Not asked'
.r="Refused"
.d="Don't know";

value walkbike
1='Walk or bike only'
2='Walk/bike with other modes'
3='Do not report walk/bike'
.r="Refused"
.d="Don't know";

value t4m4f
1='Public transportation'
2='Bike or walk'
3='Personal car/taxi'
4='Other way/ no way most of trip'
.n='Not asked'
.r="Refused"
.d="Don't know";

value transport8f
1='Very satisfied'
2='Somewhat satisfied'
3='Somewhat dissatisfied'
4='Very dissatisfied'
.n='Not asked'
.r="Refused"
.d="Don't know";

value t8s2f
1='Yes (satisfied)'
2='No (dissatisified)'
.n='Not asked'
.r="Refused"
.d="Don't know";

value howoftna
1='Often'
2='Sometimes'
3='Rarely'
4='Never'
.n='Not asked'
.r="Refused"
.d="Don't know";

value t9l2f
1='Yes (sometimes/often)'
2='No (rarely/never)'
.n='Not asked'
.r="Refused"
.d="Don't know";

value transport16f
1='Work'
2='School'
3='Errands'
4='Other reason'
5='[Vol] Did not take SBS'
.n= 'Not asked'
.r="Refused"
.d="Don't know";

/*BIKING AND TAKING THE STAIRS*/
value bike1f
1='Several times a month'
2='At least once a month'
3='A few times a year'
4='Never'
.r="Refused"
.d="Don't know";

value scaletimena
1='None of the time'
2='Some of the time'
3='Most of the time'
4='All of the time'
.n= 'Not asked'
.r="Refused"
.d="Don't know";

value bike5f
1='Apt/multi-family bldg'
2='Single-family house'
.r="Refused"
.d="Don't know";

value stairs2catf
1='Basement/1st floor'
2='2nd floor'
3='3rd floor'
4='4th floor'
5='5th floor'
6='6th floor'
7='7th floor or higher'
.n='Not Asked'
.r="Refused"
.d="Don't know";

value stairs5catf
1='Basement/1st floor'
2='2nd floor'
3='3rd floor'
4='4th floor'
5='5th floor'
6='6th floor'
7='7th floor or higher'
.n='Not Asked'
.r='Refused'
.d='Dont know'
.s='missing (Spanish language)';

value floors
1= '0 floors per weekday'
2= '1-2 floors per weekday'
3= '3-5 floors per weekday'
4= '6 floors or more per weekday'
.n= 'Not asked'
.r="Refused"
.d="Don't know";

value stairrsn
1= 'Yes'
2= 'No'
3= '[Vol]: No stairs home/work'
.n='Not asked'
.r="Refused"
.d="Don't know";

/*PHYSICAL ACTIVITY HABITS AND SELF-RATINGS*/
value acttype
1=	'Active Gaming Device'
2=	'Aerobics'
3=	'Backpacking'
4=	'Badminton'
5=	'Baseball'
6=	'Basketball'
7=	'Bicycling'
8=	'Boating'
9=	'Bowling'
10='Boxing'
11='Calisthenics'
12='Carpentry'
13='Dancing'
14='Elliptical'
15='Fishing'
16='Football'
17='Gardening'
18='Golf'
19='Gymnastics'
20='Handball'
21='Hiking'
22='Horseback riding'
23='Hockey'
24='Hunting'
25='Jogging'
26='Martial arts'
27='Mountain climbing'
28='Muscle strengthening'
29='Paddleball'
30='Pilates'
31='Racquetball'
32='Rock Climbing'
33='Rope skipping'
34='Rowing machine'
35='Rugby'
36='Running'
37='Scuba diving'
38='Skating'
39='Skate boarding'
40='Skiing, snow'
41='Sledding'
42='Snorkeling'
43='Snowshoeing'
44='Soccer'
45='Softball'
46='Spinning'
47='Squash'
48='Stair climbing/stair master'
49='Stationary bike'
50='Surfing'
51='Swimming'
52='Table tennis/ping-pong'
53='Tai Chi'
54='Tennis'
55='Treadmill'
56='Volleyball'
57='Walking'
58='Water aerobics'
59='Waterskiing'
60='Weight lifting'
61='Yoga'
62='Other'
63='Routine streches/exercises'
.n='Not asked';

value yesnoun
1='Yes'
2='No'
4='Unable to do activity'
.r="Refused"
.d="Don't know";

value habits5f
1='Very active'
2='Somewhat active'
3='Not very active'
4='Not active at all'
.r="Refused"
.d="Don't know";

value habits6f
1='Very fit'
2='Somewhat fit'
3='Not very fit'
4='Not fit at all';

value habits7f
1='Excellent'
2='Very Good'
3='Good'
4='Fair'
5='Poor'
.w='Not Asked Wave 1'
.r="Refused"
.d="Don't know";

/*CHRONIC DISEASE*/
value yesnonc
1='Yes'
2='No'
3='[Vol] Not checked'
.r="Refused"
.d="Don't know";

value bmi5f
1='Underweight'
2='Normal weight'
3='Overweight'
4='Obese'
5='Very Obese'
.r="Refused"
.d="Don't know";

value bmi4f
1='Underweight'
2='Normal weight'
3='Overweight'
4='Obese'
.r="Refused"
.d="Don't know";

value bmi3f
1='Under/Normal weight'
2='Overweight'
3='Obese'
.r="Refused"
.d="Don't know";

value chronic21f
1='Actual < Ideal'
2='Actual = Ideal'
3='Actual > Ideal';

/*BUILT ENVIRONMENT*/
value timef
1='Less than 5 minutes'
2='5 to 10 minutes'
3='More than 10, less than 30'
4='30 or more minutes'
.r="Refused"
.d="Don't know";

value howoft
1='Often'
2='Sometimes'
3='Rarely'
4='Never'
.r="Refused"
.d="Don't know";

value timena
1='Less than 5 minutes'
2='5 to 10 minutes'
3='More than 10, less than 30'
4='30 or more minutes'
.n='Not asked'
.r="Refused"
.d="Don't know";

value env16sf
1="Excellent"
2="Very Good"
3="Good"
4="Poor"
.w="Not asked Wave 1"
.r="Refused"
.d="Don't know";

value env16nsf
1="Excellent"
2="Good"
3="Fair"
4="Poor"
.r="Refused"
.d="Don't know";

value env16f
1="Excellent"
2="Good"
3="Fair"
4="Poor"
.r="Refused"
.d="Don't know";

value env16excf
1="Excellent"
2="Not Excellent"
.r="Refused"
.d="Don't know";

value env17f
1='Very expensive'
2='Somewhat expensive'
3='Just about right'
4='Inexpensive'
.r="Refused"
.d="Don't know";

value env18f
1='Often'
2='Sometimes'
3='Rarely'
4='Never'
5='[Vol: not available]'
.r="Refused"
.d="Don't know";

/*HEALTH STATUS*/
value genhlth
1='Excellent'
2='Very good'
3='Good'
4='Fair'
5='Poor'
.r="Refused"
.d="Don't know";

value gh3f
1='Excellent/Very good'
2='Good'
3='Fair/Poor'
.r="Refused"
.d="Don't know";

value days5f
1='None'
2='1-2 days'
3='3-7 days'
4='8-29 days'
5='30 days'
.r="Refused"
.d="Don't know";

value fmd
1='None'
2='0-13 days'
3='14+ days'
.r="Refused"
.d="Don't know";

/*INJURY*/
value inj1f
1='Yes, motorist'
2='Yes, bicyclist'
3='Yes, both'
4='No'
.r="Refused"
.d="Don't know";

value inj2f
1='Emergency room'
2='Doctor'
3='Overnight stay in hospital'
4='[Vol] none of the above'
.n='Not asked'
.r="Refused"
.d="Don't know";

value inj4f
1='Motor vehicle'
2='Pedestrian'
3='Another bike'
4='Fall off bike'
5='[Vol] other'
.n='Not asked'
.r="Refused"
.d="Don't know";

value inj5f
1='Emergency room'
2='Doctor'
3='Overnight stay in hospital'
4='[Vol] none of the above/not injured'
.n='Not asked'
.r="Refused"
.d="Don't know";

/*tobacco and alcohol */
value tobacco1f
1='Most days (or all days)'
2='Some days'
3='Never'
.r="Refused"
.d="Don't know";

value tobacco1smkf
1='Yes, 3+ cigarettes'
2='No'
.r="Refused"
.d="Don't know";

value alcohol1f
1='Most days (or all days)'
2='Some days'
3='Never'
.r="Refused"
.d="Don't know";

value alcohol1drinkf
1='Yes, >2 drinks'
2='No'
.r="Refused"
.d="Don't know";

/*SOCIAL NORMS*/
value norm1f
1='Yes'
2='No'
3="Vol: Don't have friends"
.r="Refused"
.d="Don't know";

value norm2f
1='Yes'
2='No'
3="Vol: Don't have family"
.r="Refused"
.d="Don't know";

value norm3dkf
1='Yes'
2='No'
3="Don't know"
.r="Refused"
.d="Don't know";

/*NYC GPAQ*/
value notaskedf
.n = "Not asked";

value catgpaqminf
1 = "Less than 30 minutes"
2 = "30 - 60 minutes"
3 = "More than 60 minutes"
.n = "Not asked";

value PA08_3Rf
1="Inactive"
2="Insufficiently Active"
3="Sufficiently Active";

value palevel3f
1="High"
2="Moderate"
3="Low";

value palevel4f
1="High"
2="Moderate"
3="Low"
4="None";

value gpaq23daysedmin_catf
1 = "Less than 30 minutes"
2 = "30 - 60 minutes"
3 = "More than 60 minutes"
.r="Refused"
.d="Don't know";

value gpaq25evesedmin_catf
1 = "Less than 30 minutes"
2 = "30 - 60 minutes"
3 = "More than 60 minutes"
.r="Refused"
.d="Don't know";

/*NYC GPAQ Addedum*/
value gpaqadd1_weekdayf
1 = "Never"
2 = "� hour or less"
3 = "1-1 � hours"
4 = "2-2 � hours"
5 = "3-3 � hours"
6 = "4-4 � hours"
7 = "5-5 � hours"
8 = "6-6 � hours"
9 = "7-7 � hours"
10= "8-9 � hours"
11= "10-12 hours"
.r="Refused"
.d="Don't know";

value gpaqadd2_weekendf
1 = "Never"
2 = "� hour or less"
3 = "1-1 � hours"
4 = "2-2 � hours"
5 = "3-3 � hours"
6 = "4-4 � hours"
7 = "5-5 � hours"
8 = "6-6 � hours"
9 = "7-7 � hours"
10= "8-9 � hours"
11= "10-12 hours"
.r="Refused"
.d="Don't know";

value gpaqadd3_1f
1 = "Alone"
2 = "With another person"
3 = "As part of a group"
.n = "Not asked"
.r="Refused"
.d="Don't know";

value gpaqadd3_2f
1 = "Alone"
2 = "With another person"
3 = "As part of a group"
.n = "Not asked"
.r="Refused"
.d="Don't know";

value gpaqadd3_3f
1 = "Alone"
2 = "With another person"
3 = "As part of a group"
.n = "Not asked"
.r="Refused"
.d="Don't know";

value gpaqadd4f
1 = "Alone"
2 = "With another person"
3 = "As part of a group"
4 = "No usual pattern"
.n = "Not asked"
.r="Refused"
.d="Don't know";

value gpaqadd5f
1 = "With a leader"
2 = "Without a leader"
3 = "No usual pattern"
.n = "Not asked"
.r="Refused"
.d="Don't know";

value gpaqadd6min_catf
1 = "0 minutes"
2 = "1-9 minutes"
3 = "10-29 minutes"
4 = "30-59 minutes"
5 = "60 or more minutes"
.r="Refused"
.d="Don't know";

/*ADMIN - GEOG*/

value intlang
1='English'
2='Spanish'
3='Russian'
4='Chinese'
.r="Refused"
.d="Don't know";

/*CHS PHYSICAL ACTIVITY QUESTIONS*/
value PA08_3R_chsf
1="Inactive"
2="Insufficiently Active"
3="Sufficiently Active";
run;

data pat_w1w2;
set PAT.pat_w1w2;
format
ANY_ACTIVITY yesno.
ANY_RECREATION yesno.
ANY_TRANSIT yesno.
ANY_WORK yesno.

/*DEMOGRAPHICS*/
agegroup agegrp.
dem3 sex.
dem4 yesno.
newrace race.
dem8 dem8f.
dem9yrsus dem9yrs.
dem10 dem10f.
dem11 dem11f.
dem12 dem12f.
dem12educ educ.
dem14 dem14f.
dem14emp emp3f.
povertygroup pov6f.
pov200 pov200f.
povgroup3 pov3f.
hhadultscat hh3f.

/*TRANSPORTATION AND COMMUTING*/
transport1 transport1f.
transport2 transport2f.
transport16sbs transport16work transport16sch transport16err yesnona.
transport4most4 t4m4f.
transport8satisfy t8s2f.
transport9like t9l2f.
transport14 transport15 yesno.
transport16_1 transport16_2 transport16_3 transport16f.

/*BIKING AND TAKING THE STAIRS*/
bike1 bike1f.
bike1ever stairs1 yesno.
bike2 bike3 bike4 scaletimena.
bike5 bike5f.
bike6 bike7 stairs3 stairs4 stairs6 stairs7 yesnona.
stairs2cat stairs2catf.
stairs5cat stairs5catf.
stairs8 stairs9 floors.
stairs10_1 stairs10_2 stairs10_3 stairs10_4
stairs10_5 stairs10_6 stairs10_7 stairs10_8 stairrsn.

/*PHYSICAL ACTIVITY HABITS AND SELF-RATINGS*/
habits1 habits2 yesno.
habits3_1 habits3_2 habits3_3 acttype.
habits3_walking habits3_wtlift habits3_run habits3_tread habits3_aerob habits3_bike habits3_cal
habits3_jog habits3_stretch habits3_yoga habits3_swim yesnona.
habits4 yesnoun.
habits5 habits5f.
habits6 habits6f.
habits7 habits7f.

/*CHRONIC DISEASE*/
chronic1 chronic3 chronic4 chronic5 chronic6 yesno.
chronic2 yesnonc.
bmicat4 bmicat4all bmi4f.

/*BUILT ENVIRONMENT*/
environment1_1 environment1_2 environment1_3 environment1_4 environment1_5 environment1_6
environment4 environment5 environment10 yesno.
environment2 environment12 timef.
environment3 environment15 howoft.
environment6 environment7 environment8 environment13 yesnona.
environment9 environment14 timena.
environment11 howoftna.
environment16ns env16nsf.
environment16 env16f.
environment16exc env16excf.
environment17 env17f.
environment18 env18f.

/*HEALTH STATIUS*/
status1 genhlth.
status1gh3 gh3f.
status3fmd3 fmd.
status6 yesno.

/*INJURY*/
injury1 inj1f.
injury2_1 injury2_2 inj2f.
injury3 yesnona.
injury4_1 injury4_2 inj4f.
injury5_1 inj5f.

/*ALCOHOL AND TOBACCO */
tobacco1 tobacco1f.
alcohol1 alcohol1f.

/*SOCIAL NORMS*/
norm1 norm1f.
norm2 norm2f.
norm3 norm3dkf.
norm4 yesno.

/*NYC GPAQ*/
gpaq1pa yesno.
gpaq4 catgpaqminf.
gpaq6pa yesno.
gpaq9 catgpaqminf.
gpaq10pa yesno.
gpaq13 catgpaqminf.
gpaq14pa yesno.
gpaq18pa yesno.
PA08_3R PA08_3R_rt PA08_3Rf.
gpaq23daysedmin_cat gpaq23daysedmin_catf.
gpaq25evesedmin_cat gpaq25evesedmin_catf.

/*NYC GPAQ Addedum*/
gpaqadd1_weekday gpaqadd1_weekdayf.
gpaqadd2_weekend gpaqadd2_weekendf.
gpaqadd3_1 gpaqadd3_1f.
gpaqadd4all gpaqadd4f.

/*ADMIN - GEOG*/
qwhich1 intlang.;
run;

proc sort data=pat_w1w2; by strata_pat; run;

proc contents data=pat_w1w2;
run;

/********Instructions for analyzing PAT data*****************
Survey data needs to be analyzed using a special procedure in SAS --
proc surveymeans - or using SUDAAN or another software package that
can handle complex survey designs.

If you are only interested in point estimates (i.e. you do not
need standard errors/confidence intervals) using the weight
option in regular SAS procedures, will give the correct point estimates. However,
in order to get confidence intervals you must use proc surveymeans or
another software program capable of accounting for the complex survey design.
************************************************************************************/

**Sample code: Standard errors will not be correct with regular SAS procs, but point
estimates will be fine. Remember to use the weight statement;
proc freq data = pat_w1w2;
tables dem3*(habits1);
weight wt_patw1w2;
run;

**Sample code for proc surveymeans - standard errors are correct.
Same point estimates as code above;
proc surveymeans data = pat_w1w2 nobs mean clm sum std clsum ;
strata strata_pat; *survey design information;
weight wt_patw1w2; *weight statement;
var habits1; *variables you are interested in analyzing;
class habits1; *all variables in var statement that are categorical;
domain dem3; *variable to see estimates stratified by;
run;

/*NOW RUN PROC DESCRIPT*/
proc descript data= pat_w1w2 filetype=sas design=strwr;
nest strata_pat; *survey strata variables*;
weight wt_patw1w2; *survey weight variable*;
var habits1 habits1; *variables you are interested in analyzing; ;
catlevel 1 2 ; *specify the levels of each variable you want *;
tables _one_ dem3; *_one_ will give you the overall total for each variable: dem3 will produce the gender-specific estimates*;
subgroup _one_ dem3 agegroup; *all variables on the tables statement must also be in the subgroup statement. agegroup is needed for age-adjustment*;
levels 1 2 4; *specify the levels of the variables above*;
/*for age-adjustment of estimate: use the US 2000 Standard Population*/
stdvar agegroup;
stdwgt 0.128810 0.401725 0.299194 0.170271;/*These weights are for agegroup total: different age adjustment weights are needed for variables that use other agegroups*/
setenv decwidth=1; /*Produce output with results rounded to 1 decimal place*/
print/style=nchs; *will print the results*;
output/filename=output12 filetype=sas tablecell=default replace; *produces an output dataset of results*;
title1 'Do you have an exercise routine, by Gender: PAT 2010-2011';
run;

/*Compute the relative standard error of the estimates:
Estimates with RSE >=0.30 or sample sizes <50 are considered unstable:
http://www1.nyc.gov/assets/doh/downloads/pdf/episrv/bes-data-reliability.pdf */
data rsecheck;
set output12; *use the output dataset created from the proc descript*;
if percent in (0.00, 100.00) then do;
if nsum >= 50 then flag = '**';
if nsum < 50 then flag = '^';
end;
if percent not in (0.00, 100.00) then do;
rse = sepercent/percent;
ciband = uppct-lowpct;
halfw = ciband/2;
if sepercent = 0.0 and ciband = 0.0 then flag='^';
else if rse =>0.5 then do;
if ciband >=6 then flag='^';
else if ciband < 6 then flag = '*';
end;
else if rse < 0.3 then do;
if nsum <50 then flag='*';
else if nsum >= 50 then do;
if halfw > 10 then flag = '*';
end;
else if 0.5 > rse >=0.3 then flag='*';
end;
run;

proc print data = rsecheck noobs;
var flag rse nsum ciband halfw percent lowpct uppct;
where flag in ('*','^', '**');
run;

/*For more details on age-adjustment, see:
Klein RJ, Schoenborn CA. Age adjustment using the 2000 projected U.S. population. Healthy
People Statistical Notes, no. 20. Hyattsville,Maryland: National Center for Health Statistics.
January 2001. http://www.cdc.gov/nchs/data/statnt/statnt20.pdf */