tags:

views:

3175

answers:

3

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

A: 

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

Bazil
+9  A: 
data _null_;
    format yymmddn8.;
    test=today();
    put test=;
run;

YYMMDD detail

adam
excellent - didn't realise about the delimiter option
Bazil
+3  A: 
%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.