Thank you all for the reply. I used some similar codes (see below) which work fine for the cases when B29,B29_B,B29_C are all non-missing. However, when only year is available (case 1), or only year and month are available (case 2), the codes will just skip these and do not calculate the difference in days. My goal actually is to classify the difference in days into 2 groups (Yes and No): Yes for 0 =< diffdays <=30 No for diffdays >30 So I modified the codes by adding the lines in bold to find the difference in year, but that will not resolve the whole issue for both cases, and needs to be further investigated. Also, if I just want to do a count for Case 1 (the cases when only year is available), and also a count for Case 2 (the cases when only year and month are available), how do I do that? proc freq, table, where=? Based on the counts/frequency, we can access and decide how to treat the cases with the missing days/months. Thank you! data want; set Revised2015; if f_B29 <0 then f_B29n = . ; else f_B29n = f_B29 ; *format f_B29n f_B29n. ; label f_B29n = "Month"; if f_B29_B <0 then f_B29_Bn = . ; else f_B29_Bn = f_B29_B ; *format f_B29_Bn f_B29_Bn. ; label f_B29_Bn = "Day"; if f_B29_C <0 then f_B29_Cn = . ; else f_B29_Cn = f_B29_C ; *format f_B29_Cn f_B29_Cn. ; label f_B29_Cn = "Year"; f_date=mdy(f_B29n,f_B29_Bn,f_B29_Cn); f_enddaten=input(f_enddate, yymmdd8.); format f_enddaten f_date mmddyy10.; f_diffdays=intck('days',f_date,f_enddaten); f_diffyears= year(f_enddaten)- f_B29_Cn; if f_diffdays <0 then f_diffdaysn = .; else if 0 <= f_diffdays <= 30 then f_diffdaysn = 1; else if f_diffdays >30 then f_diffdaysn = 2; label f_diffdaysn = "Last smoked or had a puff on a cigarette within the past 30 days" ; format f_diffdaysn YN.; run;
... View more