Friday, September 28, 2012

SAS Date Calculator Now Available


Interactive SAS Date Calculator*
Date:
Days since 1/1/1960:

Interactive SAS Datetime Calculator*
Datetime:
Seconds since midnight 1/1/1960:

*For valid results, SAS date value must be between 1582 CE and 20,000 CE on the Gregorian Calendar. Note that American Colonies and Great Britain did not adopt the Gregorian Calendar until 1752.


We have added an online, interactive SAS Date Calculator and Converter. It is available for free in this post (above). To use it, enter a date value in the first text box, and the unformatted date value (i.e., the number of days since 1/1/1960) that SAS associates with that number will appear in the second text box. The calculator also works in reverse.

We have also added a SAS Datetime Calculator and Converter, also available for free in this post (above). It works in the same way as the date calculator, except it calculates Datetimes.

It is also possible to run such conversions within SAS. Example code:

/*print date formatted as number*/
DATA _NULL_;
 d = INPUT('21DEC11'd, best12.);
 PUT d;
RUN;

/*print number formatted as date*/
DATA _NULL_;
 d = 18982;
 FORMAT d date9.;
 PUT d;
RUN;

/*print datetime formatted as number*/
DATA _NULL_;
 dt = INPUT('21DEC11 12:00:35'dt, best12.);
 PUT dt;
RUN;

/*print number formatted as datetime*/
DATA _NULL_;
 dt = 1640088035;
 FORMAT dt datetime.;
 PUT dt;
RUN;