Here is the code below. Time1 is wake up time and time2 is sleep time, then getuptime is subtraction of the two variables. You can see in the proc print table that is seems to be working except for some errors in the actual table. I added the treatment for missing because that was causing some issues, but something is still wrong with it, and I cannot find the solution, can please someone point me to the right direction, thank you /*tells SAS where to find my data set*/ libname mydata '/courses/d6670be5ba27fe300' access=readonly; options nofmterr; /*tells SAS what data set to use*/ Data new; set mydata.addhealth_public4; proc sort; by AID;/*case id*/ /*1st KEEP Statement tells sas what variables to look at*/ Keep AID Agegroup H4OD1M birthm H4ID5H H4ID6H H4SP1H H4SP1M H4SP1T H4SP2H H4SP2M H4SP2T H4SP3M H4SP3H H4SP3T H4SP4H H4SP4M H4SP4T H4SP5 H4SP6; /*tells SAS what the older data set is to use*/ Data new2; set mydata.addhealth_pds; /*2nd KEEP Statement tells sas what variables to look at*/ Keep AID bio_sex NUMETHNIC H1GI4 H1GI6A H1GI6B H1GI6C H1GI6D; proc sort; by AID;/*case id*/ data withage; merge new new2; /*gives us the variable along with the label (note if the variable is in your code some place then it needs to be in your label*/ Label AID="unique identifier" /*depression*/ H4ID5H="Have you been diagnosed with depression?" /*Categorical Nominal*/ H4ID6H="What age were you diagnosed?" /*Categorical Nominal*/ /*sleep patterns*/ H4SP1H="On the days you go to work or school, what hour do you wake up?" /*Quantitative Interval*/ H4SP1M="On the days you go to work or school, what minute do you wake up?" /*Quantitative Interval*/ H4SP1T="Do you usually wake up am or pm?" /*Categorical Nominal*/ H4SP2H="On those days, what time do you ususally go to sleep the night before (Hours)?" /*Quantitative Interval*/ H4SP2M="On those days, what minute?" /*Quantitative Interval*/ H4SP2T="On those days, what time do you usually go to sleep {pm/am}" /*Categorical Nominal*/ H4SP3M="On those days you don't have to get up at a certain time, when do you wake up {minute}?" /*Quantitative Ratio*/ H4SP3H="On those days you don't have to get up at a certain time, when do you wake up {hour}?" /*Quantitative Interval*/ H4SP3T="On those days you don't have to get up at a certain time, when do you wake up {am/pm}?" /*Categorical Nominal*/ H4SP4H="On those days, what time do you go to sleep the night or day before {hour}?" /*Quantitative Interval*/ H4SP4M="On those days, What time do you go to sleep the night or day before {minute}?" /*Quantitative Ratio*/ H4SP4T="On those days, what time do you go to sleep the night or day before {am/pm}?" /*Catigorical Nominal*/ H4SP5="How often did you have trouble falling asleep?" /*Categorical Nominal*/ H4SP6="How often did you have trouble staying asleep?" /*Categorical Nominal*/ /*demographics*/ H4OD1M="birth month" bio_sex="sex of participant" /*Categorical Nominal 1=Male 2=Female*/ Agegroup="age of participant"/*Quantitative Ratio*/ Ethnicity="Ethnicity of participant" /*Categorical Nominal*/ ; /*semicolon only at end of LAST label*/ /*subsetting to exclude people that participated in wave I but not wave IV*/ If H4OD1M GE 1 then birthm=1; If birthm=1; /*treatment for missing data*/ If bio_sex=6 then bio_sex=.; If H4ID6H GE 97 then H4ID6H=.; IF H4ID5H GE 6 then H4ID5H=.; IF H4SP1H GE 96 then H4SP1H=.; IF H4SP1M GE 96 then H4SP1M=.; IF H4SP1T GE 6 then H4SP1T=.; If H4SP2H GE 96 then H4SP2H=.; If H4SP2M GE 96 then H4SP2M=.; If H4SP2T GE 6 then H4SP2T=.; If H4SP3H GE 96 then H4SP3H=.; If H4SP3M GE 96 then H4SP3M=.; If H4SP3T GE 6 then H4SP3T=.; If H4SP4H GE 96 then H4SP4H=.; If H4SP4M GE 96 then H4SP4M=.; If H4SP4T GE 6 then H4SP4T=.; Agegroup=2008-H4OD1Y; /*creating secondary variable that is participants ethnicity (note this something that each of you are going to want to have so you can describe your sample by ethnicity)*/ NUMETHNIC=SUM (of H1GI4 H1GI6A H1GI6B H1GI6C H1GI6D); If NUMETHNIC GE 2 THEN ETHNICITY=1;/*MULTIPLE RACE/ETHNICITY ENDORSED*/ ELSE IF H1GI4=1 THEN ETHNICITY=2;/*HISPANIC OR LATINO*/ ELSE IF H1GI6B=1 THEN ETHNICITY=3;/*BLACK OR AFRICAN AMERICAN*/ ELSE IF H1GI6C=1 THEN ETHNICITY=4;/* AMERICAN INDIAN OR NATIVE AMERICAN*/ ELSE IF H1GI6D=1 THEN ETHNICITY=5;/*ASIAN OR PACIFIC ISLANDER*/ ELSE IF H1GI6A=1 THEN ETHNICITY=6; /*WHITE*/ ELSE ETHNICITY=7; /*OTHER*/ /*Subsetting*/ If agegroup le 28; /*recode dummy codes*/ If H4ID6H NE 97 and H4ID6H=. then H4ID6H=0; /*skip*/ proc format ; picture miltime low-high = '%0H%0M' (datatype=time) ; run; data new; set mydata.addhealth_public4; IF H4SP1H GE 96 then H4SP1H=.; IF H4SP1M GE 96 then H4SP1M=.; IF H4SP1T GE 6 then H4SP1T=.; If H4SP2H GE 96 then H4SP2H=.; If H4SP2M GE 96 then H4SP2M=.; If H4SP2T GE 6 then H4SP2T=.; time1=hms(mod(h4sp1h,12),h4sp1m,0); if h4sp1t=2 then time1=time1+'12:00:00't; time2=hms(mod(h4sp2h,12),h4sp2m,0); if h4sp2t=2 then time2=time2+'12:00:00't; getup_time=time1-time2; format time1 time2 getup_time miltime4.; run; /*tells SAS how to sort the data by id number*/ proc sort; by AID; /*proc print to check secondary variable*/ /*proc print; var time1 time2 getup_time;*/ /*tells SAS that I want frequency tables and for what variables*/ proc freq; tables time1 time2 getup_time; /* H4SP1H H4SP1M H4SP1T H4SP2H H4SP2M H4SP2T H4SP3H H4SP3M H4SP3T H4SP4H H4SP4M H4SP4T H4SP5 H4SP6 bio_sex H4ID5H H4ID6H WoScWake WoScSleep NoWoScWake NoWoScSleep */ /*tells SAS to analyze the data*/ run attached are the pics that show the table get up table with the error and the second one the log with no errors table with error log with no errors
... View more