Question

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...

Was it helpful?

Solution

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

YYMMDDxw. documentation

OTHER TIPS

%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.

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!!

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

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'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top