%let dt = Today();
DATA _NULL_;
DCS3YR= put(Intnx('YEAR',&dt,-3,'S'),date9.);
call SYMPUTX('DCS3YR', DCS3YR);
run;
%put &DCS3YR;
%let DCS3YR_d9 =%sysfunc(inputn(&dcs3yr,date9.),date9.);
%put &DCS3YR_d9;
Did you mean:
%let DCS3YR_d9 =%sysfunc(put(inputn(&dcs3yr,date9.)),date9.);
Code was not tested.
I would say it depends on what you mean by "reached a date. macro variable". Or what you expect for result. You don't say what you want or expect.
You have created text in the date9 appearance. With points for a complicated way of duplicating:
%let DCS3YR_d9= &DCS3YR ;
If you expect to manipulate "dates" using macro language it much better NOT to format the values.
Whenever you need a date value for calculations or comparisons, it is much better to not format the macro variable in any way. See this:
%let cutoff = %sysfunc(intnx(year,%sysfunc(today()),-3,s));
data want;
set have;
where date > &cutoff.;
run;
Formatted values in macro variables are only needed if you use the macro variable for display, e.g. in a TITLE statement.
@Kurt_Bremser wrote:
Formatted values in macro variables are only needed if you use the macro variable for display, e.g. in a TITLE statement.
Or to match an external file name for input/output rules.
Macro variables are just strings. You have made two macro variables with the same 9 characters.
If you have a macro variable with a value that the DATE informat understands then you can use as a date literal in your code by adding quotes and the letter d. So here is another convoluted way to make a copy of your DCS3YR macro variable.
%let copy2 = %sysfunc(putn("&dcs3yr"d,date9.));
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.