{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# lesson06 - Lesson 6 Topics Working with dates Functions in...

This preview shows pages 1–8. Sign up to view the full content.

Lesson 6 - Topics Working with dates Functions in the DATA step Working with ARRAYS Programs 8-10 in course notes C&S 4:A-C;17:A-D;18 LSB 3:2-4,8-9,11

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Dates Come in Many Ways 10/18/04 18/10/04 10/18/2004 18OCT2004 101804 October 18, 2004 Need to know how to read-in dates and then work with them
What do you want to do with dates? Display them Compare two dates - find the number of days between 2 dates ndays = date2 - date1; Will this work? Problem: dates do not subtract well What if: date2 = 03/02/2003 date1 = 08/02/2002 ========== -05/00/0001

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
DATA dates; INFILE DATALINES ; INPUT @1 brthdate mmddyy10. ; DATALINES ; 03/03/1971 02/14/1956 01/01/1960 ; PROC PRINT ; VAR brthdate; PROC PRINT ; VAR brthdate; FORMAT brthdate mmddyy10. ; ------------------------------------------------------ Obs brthdate 1 4079 2 -1417 3 0 Obs brthdate 1 03/03/1971 2 02/14/1956 3 01/01/1960 Jan 1, 1960
When you read in a variable with a date informat : SAS makes the variable numeric SAS assigns the value relative to January 1, 1960 You must assign a date format to the variable to display as a date. This makes it easy to subtract two dates to get the number of days between them. dayselapsed = date2 – date1;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
* Program 8 ; DATA age; INFILE ‘C:\SAS_Files\tomhs.data' ; INPUT @ 14 randdate mmddyy10. @ 34 brthdate mmddyy10. @ 74 date12 mmddyy10. ; agedays = randdate - brthdate ; ageyrs = (randdate - brthdate)/ 365.25 ; ageint = INT( (randdate - brthdate)/ 365.25 ); * Can also use YRDIF function; ageyrsX = YRDIF(brthdate,randdate, 'Actual' ); agetoday= (TODAY() - brthdate)/ 365.25 ; ageendst= (MDY( 02 , 28 , 1992 ) - brthdate)/ 365.25 ; daysv12 = date12 - randdate; if ABS(daysv12 - 365 ) = . then window12 = . ; else if ABS(daysv12 - 365 ) < 31 then window12 = 1 ; else if ABS(daysv12 - 365 ) >= 31 then window12 = 2 ; yrrand = YEAR(randdate);
PROC PRINT DATA =age ( obs = 10 ); VAR brthdate randdate agedays ageyrs ageyrsX ageint agetoday; TITLE 'Printing Dates Without a Date Format' ; RUN ; PROC PRINT DATA =age ( obs = 10 ); VAR brthdate randdate agedays ageyrs ageyrsX ageint agetoday; FORMAT brthdate mmddyy10. randdate mmddyy10. ; TITLE 'Printing Dates With a Date Format' ; RUN ;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 28

lesson06 - Lesson 6 Topics Working with dates Functions in...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online