BookmarkSubscribeRSS Feed
Q1983
Lapis Lazuli | Level 10
data _null_;

call symput('tday',put(today(),mmddyy8.));
run;
%put &tday ;

data test;
my_date = INTNX('MONTH',&tday,1,'SAMEDAY') ;
format my_date mmddyy8.;
run;

I want today's date exactly one month from now.  Code runs without issue but is producing 2/1/60 (today is 2/18/22)  I want in this case to show 3/18/22

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

Macro variables containing date values, date/time values or time values should NOT be formatted (Maxim 28) for arithmetic or logical operations.

 

data _null_;
call symputx('tday',today());
run;
%put &tday ;

data test;
my_date = INTNX('MONTH',&tday,1,'SAMEDAY') ;
format my_date mmddyy8.;
run;

Why? Because the INTNX function cannot work with &tday as you have created it, because the value 02/18/22 is interpreted as 2 divided by 18 divided by 22. However, the unformatted value of &tday (as I have programmed it) is 22694, which is indeed exactly what INTNX needs, this is interpreted as a valid legal SAS date. (Valid legal SAS dates are the number of days since 01JAN1960, that's what 22694 represents).

 

Please, for clarity, you do not have a macro in your code. You have a macro variable. These are not the same. Please do not refer to macro variables as macros or vice versa, this is incorrect. Clarity is always good.


Adding: it is not the fault of the macro variable here, as your title implies ... it is a programming error. A good method to use is to first write code without macro variables and get that to work properly, and then creating code that works with macro variables should be relatively easy. Most people don't do this, and they should! But if your code doesn't work without macro variables, then it will never work with macro variables. 

 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 657 views
  • 2 likes
  • 2 in conversation