user10745594
user10745594

Reputation:

How to reformat dates?

Hello currently my dates are stored as numeric in the form of 40547. How can I convert these to MMDDYY10.?

data SevenSec11;
      set Seven11;
      DateRecieved = input(put(DateRecieved, 8.), MMDDYY10.);
      format DateRecieved MMDDYY10.;
 run;

Upvotes: 0

Views: 107

Answers (1)

Tom
Tom

Reputation: 51566

How to convert it depends on what the value represents. If it is dates as stored by Excel then change the offset value. If it is supposed to represent MMDDYY values then use the Z6. format in your PUT() function call.

data test;
  input num ;
  sasdate1 = num + '30DEC1899'd ;
  sasdate2 = input(put(num ,z6.),mmddyy10.);
  format num comma7. sasdate: yymmdd10. ;
cards;
40547
;

Result:

Obs        num      sasdate1      sasdate2

 1      40,547    2011-01-04    1947-04-05

Note that using Y-M-D order for dates will eliminate confusion that truncated leading zeros can cause. It will also prevent half of your audience from confusing April 5th with May 4th.

Upvotes: 1

Related Questions