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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.