BookmarkSubscribeRSS Feed
AnandSahu
Calcite | Level 5

    Hi All,

Can we convert a number into a sas date for example I have a number i.e. 375 want to calculate a date on this given day without using format.

Regards

Anand

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Really depends.  What does 375 mean?  Is it days since Jan2014, minutes since midday??

AnandSahu
Calcite | Level 5

This is just a number. Actually it was asked in an interview to me. I told them by using format, a can be converted by this number but they marked my answer as incorrect. So that is why I am approaching this community whether in actual a number can be converted in to date without using a format or informat statement.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, if you look at the documentation around SAS storage of dates/times you will see that they are indeed a number, dates for example are the number of days since January 1, 1960.  So if we assume that the 375 is a date, then we would need to do 01JAN1960 + 375 days = 10JAN1961.  You can check this with the small bit of code below.  Not sure why the format was a fail, maybe because you didn't explain the underlying mechanics?

data temp;

  attrib d1 d2 format=date9. d3 format=best.;

  d1='01JAN1960'd;

  d2=intnx('day',d1,375,'same');

  d3=375;

  format d3 date9.;

run;


How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1420 views
  • 0 likes
  • 2 in conversation