TITLE ' How to convert numeric date into SAS date value '; TITLE1 'and calculate the difference between two dates '; /* Programmer: Tim fj Tolson Feb. 17, 1992 */ /* User Services, Academic Computing, Univ of Va */ data original; input id 1-3 dob 5-10 intake 12-17 wifedob 19-24; /* NOTE: dates are in YYMMDD format but are being read in as a number */ /* Not with one of SAS's date formats, so 560816 is treated as 560,816 */ CARDS; 101 560816 900911 561231 102 620816 900911 . 103 591022 900911 590903 104 521129 900925 561002 105 510804 910115 541229 106 550423 910115 600527 108 700530 910205 690914 109 660916 910205 611021 110 631001 910219 610812 111 471111 910226 500210 112 590809 910226 550328 113 490110 910326 710222 114 330412 910326 . 115 511108 910402 . 116 510220 910903 530113 117 620921 910903 707708 118 450821 910903 . 119 511017 910917 640206 120 710218 910924 . 121 600701 910924 . 122 570118 911015 . 123 600710 911112 . 124 720308 . 710503 126 580201 920107 . 127 570909 920109 . 129 691007 920121 . 128 340929 920114 . ; /* semi-colon marks end of raw data */ data tmp; set original; /* The computation below converts the original DOB variables from */ /* numeric format (the 6.) to SAS date format ---This example */ /* also shows how to change a format of an existing variable to a */ /* new SAS format. */ newdob=INPUT(PUT(dob,6.), YYMMDD6.); newintak = INPUT(PUT(intake,6.), YYMMDD6.); /* Now that the two dates are in SAS date value format, SAS can */ /* calculate the difference between the two dates correctly! */ diff=newintak-newdob ; /* difference between dates in days */ diffyr=diff/365.25; /* difference between dates in years */ proc print ; var id dob newdob intake newintak diff diffyr; /* Finally, to show you how to REFORMAT a variable for printing */ /* here's how to get the dates to print nicely. Notice that you */ /* start with the new variables that are in SAS date value format! */ data tmp2 ; FORMAT newdob worddate18. newintak mmddyy8. ; set tmp; proc print ; var id dob newdob intake newintak diff diffyr; /* If you need assistance with SAS please contact the statistical */ /* consultants at the ITC Research Computing Support Center at */ /* 244 Wilson Hall - 243-8000 M-F 9-5 or */ /* mail res-consult@virginia.edu */