/************************************************ Using Dates in SAS FILENAME: date.sas ************************************************************/ options formchar="|----|+|---+=|-/\<>*"; options pageno=1; title; data survey; infile "survey.dat"; input Pt_num DateRec :mmddyy8. Phone FstAppt ConvApp Staff Confer Txhelp AddSvc Tx_Loc FeelTx Wait ConTime RxExpl Confcare; lastdate="01FEB1997"D; today = date( ); days = lastdate - daterec; years = (lastdate - daterec)/365.25; format daterec today mmddyy10. lastdate date9.; run; title "Printout Showing Dates with Date Formats"; proc print data=survey(obs=10); var pt_num daterec lastdate today days years; run; title "Contents Showing Formats for Date Variables"; proc contents data=survey; run; /*USING THE MDY FUNCTION TO READ A DATE*/ data dates; length name $12; input name $ bmon bday byr intmon intday intyr; if bday = . then bday = 15; if intday = . then intday = 15; birdate = mdy(bmon,bday,byr); intdate = mdy(intmon,intday,intyr); intage = int((intdate-birdate)/365); format birdate intdate mmddyy10.; cards; Roger 12 12 84 9 3 94 Samantha 1 20 85 9 15 94 Henry 10 6 83 10 2 94 William 4 17 82 10 5 94 Petra 6 . 83 9 14 94 ; proc print data=dates; title 'Printing Dates Using SAS Date Formats'; run; proc print data=dates; format birdate intdate ; title 'Printing Dates as Ordinary Numeric Values'; run; /*How to handle the Year 2000 problem*/ options yearcutoff = 1900; data testdate; input chkdate :MMDDYY8.; format chkdate mmddyy10.; cards; 01/01/50 01/01/49 01/01/01 01/01/98 01/01/00 ; proc print data=testdate; title "Printout of Dates with yearcutoff at 1900"; run;