/************************************************** homework2.sas ***************************************************/ libname b510 v9 "e:\510\homework"; /*Question 1: Find out which IDs have more than one value*/ proc freq data=b510.hrtrate2; tables id; run; /*Question 1: Create a new data set that has no duplicates, and that has no missing values for ID, and exclude the baby from the data set (id=59) */ data work.newhrtrate2; set b510.hrtrate2; if id not in (.,13,17,19,20,60,59); run; /*Question 2: Merge the two data sets*/ proc sort data=b510.hrtrate1 ; by id; run; proc sort data=work.newhrtrate2 ; by id; run; data b510.combine; merge b510.hrtrate1 work.newhrtrate2; by id; hrdiff = hrtrate2-hrtrate1; run; /*Question 3: Descriptive Statistics on hrtrate1, hrtrate2 and hrdiff*/ proc means data=b510.combine; var hrtrate1 hrtrate2 hrdiff; run; /*Question 4: Descriptive Stats for each level of RAN */ proc means data=b510.combine; class ran; var hrtrate1 hrtrate2 hrdiff; run; /*Question 5: Boxplots for those who ran and did not run*/ proc sort data=b510.combine; by ran; run; proc boxplot data=b510.combine; where id not=59; plot hrtrate1*ran / boxstyle=schematic; plot hrtrate2*ran / boxstyle=schematic; plot hrdiff*ran / boxstyle=schematic; run; /*Question 6: Independent Samples t-tests*/ proc ttest data=b510.combine; class ran; var hrtrate1 hrtrate2 hrdiff; run; /*Question 7: Paired t-tests for those who ran and did not run*/ proc ttest data=b510.combine; by ran; paired hrtrate2*hrtrate1; run; /*Question 8: One-sample t-test for hrdiff done separately for those who ran and did not run using a By statement. by RAN; */ /*Method 1 for one-sample ttest, using Proc Univariate*/ proc univariate data=b510.combine; by ran; var hrdiff; histogram; run; /*Method 2 for one-sample t-test, using Proc ttest*/ proc ttest data=b510.combine; by ran; var hrdiff; run; /******************************************************** Another way to get rid of observations in the hrtrate2 data set that have more than one value for an ID. This method is done completely by programming, without having to tabulate anything by hand. *********************************************************/ /*First, get the number of observations per id in a new data set called TABDAT (variable=count)*/ proc freq data=b510.hrtrate2 noprint; tables id / out=tabdat; run; proc print data=tabdat; where count>1; run; /*Now, merge the data (TABDAT) with the number of obs per ID with the original time 2 data set (B510.HRTRATE2). Keep the cases with count < 2 and not missing id and not the baby (id=59). */ proc sort data=b510.hrtrate2; by id; run; data newhrtrate2; merge b510.hrtrate2 tabdat; by id; if id not in (.,59) and count < 2 then output; run; /*Now, merge b510.hrtrate1 and newhrtrate2*/ data b510.combine; merge b510.hrtrate1 newhrtrate2; by id; hrdiff=hrtrate2-hrtrate1; run;