Here's how I enter and work with a date as a macro variable:
%let x = %SYSEVALF('01jan2012'd);
%put &x; *see the date as sas sees it;
%put %SYSFUNC(putn(&x,yymmn.)); *see the date as yyyymm;
This is great, but I'm tired of entering dates as '01jan2012'd
. In special circumstances, I might want to pass in the date as a macro variable y
, where y
is in the form yyyymmdd
, something like this:
%let y = 20120101;
%let x = %SYSEVALF(&y);
Of course, this doesn't work. So, given y
, what should I use instead of %let x = %SYSEVALF(&y);
to have x
as a macro variable for the date as sas sees dates?
First off: if you're entering them in by hand, use SAS conventions. Enter it as '01JAN2012'd. It is more quickly readable than a YYYYMMDD value, for one, and regardless of that it is what other SAS programmers expect.
Second: I wouldn't use %SYSEVALF() in either case. %let x='01JAN2012'd; is sufficient in almost every case, and odds are if it's not then you're doing something in a less efficient or standard way. Unless you're intending to use 18993 in text somewhere (in which case, okay, you can use this) '01JAN2012'd is the right way to store this in a macro variable - let SAS convert it to 18993 later.
Finally:
%let y=20120101;
%let x=%sysfunc(inputn(&y,YYMMDD8.));
is the simplest way to do what you're asking.