1 The SAS System 11:14 Monday, June 12, 2000 NOTE: Copyright (c) 1999 by SAS Institute Inc., Cary, NC, USA. NOTE: SAS (r) Proprietary Software Version 8 (TS M0) Licensed to UNIVERSITY OF VIRGINIA - INFO TECH COMMUNICATIONS, Site 0001639011. NOTE: This session is executing on the AIX 3 platform. University of Virginia Information Technology and Communication SAS News Our SAS license includes these SAS modules: Base, AF, ASSIST, CONNECT, EIS, ETS, FSP, GIS, GRAPH, IML, INSIGHT, LAB, OR, QC, SHARE, SPECTRAVIEW, STAT, and ACCESS FOR DB2/6000, INFORMIX, INGRESS, ORACLE, PC FILE FORMATS, and SYBASE and SQL Server. Y2K Note: We have set the YEARCUTOFF variable to 1920. Two-digit years are assumed to be between 1920 and 2019 unless you set the YEARCUTOFF variable differently. For helpful information about Y2K and YEARCUTOFF, see http://www.itc.virginia.edu/research/docs/SASY2K.html NOTE: SAS initialization used: real time 1.78 seconds cpu time 0.09 seconds NOTE: AUTOEXEC processing beginning; file is /sas8/autoexec.sas. NOTE: AUTOEXEC processing completed. 1 TITLE ' How to convert numeric date into SAS date value '; 2 TITLE1 'and calculate the difference between two dates '; 3 4 /* Programmer: Tim fj Tolson Feb. 17, 1992 */ 5 /* User Services, Academic Computing, Univ of Va */ 6 7 data original; 8 input id 1-3 dob 5-10 intake 12-17 wifedob 19-24; 9 10 /* NOTE: dates are in YYMMDD format but are being read in as a number */ 11 /* Not with one of SAS's date formats, so 560816 is treated as 560,816 */ 12 13 CARDS; NOTE: The data set WORK.ORIGINAL has 27 observations and 4 variables. NOTE: DATA statement used: real time 0.39 seconds cpu time 0.02 seconds 41 ; /* semi-colon marks end of raw data */ 42 43 data tmp; 2 The SAS System 11:14 Monday, June 12, 2000 44 set original; 45 46 /* The computation below converts the original DOB variables from */ 47 /* numeric format (the 6.) to SAS date format ---This example */ 48 /* also shows how to change a format of an existing variable to a */ 49 /* new SAS format. */ 50 51 newdob=INPUT(PUT(dob,6.), YYMMDD6.); 52 newintak = INPUT(PUT(intake,6.), YYMMDD6.); 53 54 /* Now that the two dates are in SAS date value format, SAS can */ 55 /* calculate the difference between the two dates correctly! */ 56 57 diff=newintak-newdob ; /* difference between dates in days */ 58 diffyr=diff/365.25; /* difference between dates in years */ 59 NOTE: Missing values were generated as a result of performing an operation on missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 57:14 1 at 58:12 NOTE: There were 27 observations read from the dataset WORK.ORIGINAL. NOTE: The data set WORK.TMP has 27 observations and 8 variables. NOTE: DATA statement used: real time 0.48 seconds cpu time 0.02 seconds 60 proc print ; var id dob newdob intake newintak diff diffyr; 61 62 /* Finally, to show you how to REFORMAT a variable for printing */ 63 /* here's how to get the dates to print nicely. Notice that you */ 64 /* start with the new variables that are in SAS date value format! */ 65 NOTE: There were 27 observations read from the dataset WORK.TMP. NOTE: The PROCEDURE PRINT printed page 1. NOTE: PROCEDURE PRINT used: real time 0.08 seconds cpu time 0.00 seconds 66 data tmp2 ; 67 FORMAT newdob worddate18. newintak mmddyy8. ; 68 set tmp; 69 NOTE: There were 27 observations read from the dataset WORK.TMP. NOTE: The data set WORK.TMP2 has 27 observations and 8 variables. NOTE: DATA statement used: real time 0.04 seconds cpu time 0.02 seconds 70 proc print ; var id dob newdob intake newintak diff diffyr; 71 72 /* If you need assistance with SAS please contact the statistical */ 73 /* consultants at the ITC Research Computing Support Center at */ 74 /* 244 Wilson Hall - 243-8000 M-F 9-5 or */ 3 The SAS System 11:14 Monday, June 12, 2000 75 /* mail res-consult@virginia.edu */ 76 NOTE: There were 27 observations read from the dataset WORK.TMP2. NOTE: The PROCEDURE PRINT printed page 2. NOTE: PROCEDURE PRINT used: real time 0.02 seconds cpu time 0.00 seconds NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: The SAS System used: real time 3.09 seconds cpu time 0.15 seconds