BookmarkSubscribeRSS Feed
Kiteulf
Quartz | Level 8

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

5 REPLIES 5
Shmuel
Garnet | Level 18

Did you mean:

%let DCS3YR_d9 =%sysfunc(put(inputn(&dcs3yr,date9.)),date9.);

Code was not tested.

ballardw
Super User

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.

 

Kurt_Bremser
Super User

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.

ballardw
Super User

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

Tom
Super User Tom
Super User

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

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1348 views
  • 2 likes
  • 5 in conversation