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) and on the right-hand margin of this page. 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) and on the right-hand margin of this page. 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;

13 comments:

  1. You're welcome! Glad it was helpful.

    ReplyDelete
  2. This by FAR the most overwhelmingly stupid aspect of SAS. Thanks for your page. Now I want the 30 minutes I just wasted trying to do this on my own back from Mr Goodnight.

    ReplyDelete
  3. Thanks for your comment -- indeed, there are some things in SAS that aren't so intuitive, but I'm glad the page was helpful. By the way, if you have any other ideas for other SAS topics that could go on here, feel free to let me know and I'll see if I can add something about them.

    ReplyDelete
  4. When I put 0 into the Datetime Calculator I get Thu Dec 31 1959 21:00:00 PST. Is that because I am on Pacific time?

    ReplyDelete
    Replies
    1. Hi donf, yes that's because you are on Pacific time. Because of your comment, I've just modified the datetime calculator to make it timezone-agnostic. Please give that a try and let me know if the issue appears to be fixed. Thanks for your input.

      Delete
    2. I still get Thu, 31 Dec 1959 21:00:00 (but the PST is gone).

      Delete
    3. Hi donf, thanks for your note. After making some more changes and testing multiple time zone settings in my OS, I think the problem appears to be fixed. But please check it out and please do let me know if you see any more problems with it. Thank you again, best wishes.

      Delete
    4. Hal, you were successful and the Datetime calculator now works correctly on the west coast. Thanks. However, the Date calculater still returns Dec 31, 1959. Looks like it needs the same fix.

      Delete
    5. Hi donf, thank you for your most recent comment. I've made the modification. If you have any other comments/questions, please do let me know.

      Delete
  5. Both calculators work in my time zone now. Thanks for creating this and for the adjustments.

    ReplyDelete
    Replies
    1. You're welcome donf, and thank you for your comments.

      Delete