/*Question 1: Create New Data Set with New Variables*/ options pageno=1; libname b510 v9 "e:\510\homework"; data b510.combine2; set b510.combine; /*This is the ID for the baby. Delete this case from the data set*/ if id = 59 then delete; if hrs_exercise not=. then do; if hrs_exercise<=1 then activity=1; if hrs_exercise>=2 and hrs_exercise<=4 then activity=2; if hrs_exercise>4 then activity=3; end; if hrtrate1 not=. then do; if hrtrate1 >=85 then hi1=1; else hi1 = 2; end; if hrtrate2 not=. then do; if hrtrate2 >=85 then hi2=1; else hi2 = 2; end; if ran = 1 then rran=1; if ran = 0 then rran=2; /***************************** Recode Gender. Not required. ******************************/ if gender="m" then gender="M"; if gender="f" then gender="F"; run; /*Question 2: Create formats for new variables. No format is necessary for GENDER, since it is a character variable.*/ proc format; value actfmt 1="1: <=1" 2="2: 2-4 hours" 3="3: >4 hours"; value hifmt 1="1:High" 2="2:Not High"; value rranfmt 1="1:Yes" 2="2:No"; value $genfmt "M" = "Male" "F" = "Female"; run; /*Question 3: Check recodes*/ proc means data=b510.combine2; title "Question 3: Proc Means for the Entire Data Set"; run; proc means data=b510.combine2; class activity; var hrs_exercise; title "Question 3: Proc Means to Check ACTIVITY"; run; proc means data=b510.combine2; class hi1; var hrtrate1; title "Question 3: Proc Means to Check HI1"; run; proc means data=b510.combine2; class hi2; var hrtrate2; title "Question 3: Proc Means to Check HI2"; run; proc means data=b510.combine2; class rran; var ran; title "Question 3: Proc Means to Check RRAN"; run; /*Note: A better way to check the recode for RRAN uses proc freq to compare the code for RAN to the code for RRAN*/ proc freq data=b510.combine2; tables ran*rran/ list; title "Question 3: Proc Freq to Check RRAN"; run; /*Question 4: Tabulate new variables, using formats*/ proc freq data=b510.combine2; tables ran rran activity hi1 hi2 gender; format activity actfmt. hi1 hi2 hifmt. rran rranfmt. gender $genfmt.; title "Question 4: Tabulation of New Variables"; run; /*Question 5: Crosstab of GENDER by HI1 and ACTIVITY by HI1. Note: Use a chisq test for each crosstabulation, and a trend test for ACTIVITY by HI1. Trend test is appropriate when one variable is Ordinal and the other is Binary */ proc freq data=b510.combine2; tables gender*hi1 / chisq ; format hi1 hifmt.; title "Question 5: Crosstab of GENDER by HI1"; run; proc freq data=b510.combine2; tables activity*hi1 / chisq trend; format activity actfmt. hi1 hifmt.; title "Question 5: Crosstab of ACTIVITY by HI1, with TREND Test"; run; /*Question 6: Crosstab RRAN*HI2. Calculate chi-square test of independence and estimate relative risk and odss ratio*/ proc freq data=b510.combine2; tables rran*hi2 / chisq relrisk; format rran rranfmt. hi2 hifmt.; title "Question 6: Crosstab of RRAN by HI2"; title2 "With Odds Ratio and Relative Risk"; run; /*Question 7: Gender*rran*hi2 threeway xtab*/ proc freq data=b510.combine2; tables gender*rran*hi2 / chisq relrisk cmh; format rran rranfmt. hi1 hi2 hifmt.; title "Question 7: Crosstab of RRAN by HI2 for each GENDER"; title2 "Get CMH statistics for combined estimates across GENDER"; run;