Hello
Let's say that the user (person who run the sas program) define a sas macro varaible
%let lastScore=1901;
How can we create another sas macro varaible that is called OneMonBefore that wil get value 1812 (one month before value of lastScore)
How can we do it in open code?
thanks
Joe
Use the functions INTNX() to increment the month one back. You can use INPUTN() and PUTC() to convert to a date or use MDY() and SUBSTR() to convert it to a date. If may be easier overall to store it as a date entirely but you can customize it to your needs.
Some common examples of macro functions with dates and time is here:
https://communities.sas.com/t5/SAS-Communities-Library/Macro-Variables-of-Date-and-Time/ta-p/475194
@Ronein wrote:
Hello
Let's say that the user (person who run the sas program) define a sas macro varaible
%let lastScore=1901;
How can we create another sas macro varaible that is called OneMonBefore that wil get value 1812 (one month before value of lastScore)
How can we do it in open code?
thanks
Joe
Consider creating the 1812 value at the same place you created the 1901 value, instead of in open code.
Let's assume that you want to interpret 1901 as meaning January of 2019.
It is easy to use the INTNX() function to move a date by one month, put you need an actual date value.
%let lastScore=1901;
%let OneMonBefore=%sysfunc(intnx(month,%sysfunc(inputn(&lastscore.01,yymmdd)),-1),yymmn4);
Result:
2285 %put &=lastscore &=onemonbefore ; LASTSCORE=1901 ONEMONBEFORE=1812
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.