17

How do I convert a SAS date such as "30JUL2009"d into YYYYMMDD format (eg 20090730)?

So for instance:

data _null_;
  format test ?????;
  test=today();
  put test=;
run;

Would give me "test=20090730" in the log...

andrey_sz
  • 751
  • 1
  • 13
  • 29
Allan Bowe
  • 12,306
  • 19
  • 75
  • 124

5 Answers5

26
data _null_;
    format test yymmddn8.;
    test=today();
    put test=;
run;

YYMMDDxw. documentation

adam
  • 368
  • 3
  • 9
14
%let expectdate1=%sysfunc(putn(%eval(%sysfunc(today())-1),yymmddn8.));

You want to use the format yymmddn8. The 'n' means no separator.

Per http://support.sas.com/kb/24/610.html you can specify B for blank, C for colon, D for dash, N for no separator, P for period, or S for slash.

3

There is this one that should do the trick too

%let today=%sysfunc(today(),yymmddn8.);
%put &today.;

Everything on the link below

https://communities.sas.com/thread/60111

Andy K
  • 4,944
  • 10
  • 53
  • 82
2

here's how I did it in macro, but surely there must be a format??!!!

%let today=%sysfunc(compress(%sysfunc(today(),yymmddd10.),'-'));

its weird - the INFORMAT yymmdd8. gives YYYYMMDD result, whereas the FORMAT yymmdd8. gives a YY-MM-DD result!!

Allan Bowe
  • 12,306
  • 19
  • 75
  • 124
0

You can see all date and time formats in Help tab when you enter 'date' to Index tab and then selecr 'date and time formats'

andrey_sz
  • 751
  • 1
  • 13
  • 29