Concept of Date in SAS

How to deal with dates in SAS


Let's learn all the important functions dealing with Time and Date in SAS.  Also we are covering the background processing of date and time variables in SAS.

So get ready for the date and be on time !





How SAS reads the date ?


SAS reads date as number of days from 01Jan1960. Well, this is considered as the default base dates of SAS.  We have already explained about formats and informats of dates in on of our previous articles.

Run the following code and you will will get a data as shown on the right side.

Data Data_wid_dates;
input dob : date9.;
DOB_formatted = dob;
format DOB_formatted date9.;
cards;
23Jan2014
01Feb1961
01Jan1960
02Jan1960
31Dec1959
;
proc Print;
Run;

It is clear from the dataset, that SAS reads the base date as ZERO and any date prior to the base date is considered as negative.

SAS is very intelligent, and the same can be seen with the following example. Here year is not having all 4 digits, but only last two. Still the software is capable to understand the dates.

Data Data_wid_dates;
input dob : date7.;
DOB_formatted = dob;
format DOB_formatted date9.;
cards;
23Jan14
01Feb61
01Jan60
02Jan60
31Dec59
;
proc Print;
Run;

But try the following code now. What do you expect SAS would read first date as ?

23 Jan 1928 or 23 Jan 2028

Data Data_wid_dates;
input dob : date7.;
DOB_formatted = dob;
format DOB_formatted date9.;
cards;
23Jan28
01Feb61
01Jan60
02Jan60
31Dec59
;
proc Print;
Run;

Can you imagine, how SAS has interpreted it into year 1928 but not 2028 ?

Basically, there is one more concept you need to know about the date processing in SAS. There is a yearcutoff set in the background. In SAS 9.4 version, in my laptop, the default yearcutoff in is 1926. In earlier day, when I started leaning SAS, it used to be 1920.

You can check the yearcutoff  in your version of SAS using : (check log after running)

proc options option = yearcutoff ; run; 

Now while 1926 is yearcutoff, SAS considers a span of 100 years i.e. from year 1926 to year 2025 as years in considerations. So 24 would become 2024, 76 would become 1976.

You can also customize the yearcutoff using global option : options yearcutoff = 1930;


Work with dates now (Click please) >>>


No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.