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

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
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
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
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
Background image of page 3

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

View Full DocumentRight Arrow Icon
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
Background image of page 4
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;
Background image of page 5

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

View Full DocumentRight Arrow Icon
* 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);
Background image of page 6
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 ;
Background image of page 7

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

View Full DocumentRight Arrow Icon
Printing Dates Without a Date Format Obs brthdate randdate
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/21/2011 for the course PUBH 6420 taught by Professor Greggrandis during the Fall '11 term at University of Florida.

Page1 / 28

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

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online