Hello
User define 2 macro variables in format YYMM.
The task is to create 2 more macro variables that are calculated automatically.
What is the way to calculate them please?
First macro var will get value of start of month of From_YYMM
Second macro var will get value of End of month of until_YYMM
/***USer Define macro variables***/
%let From_YYMM=2212;
%let until_YYMM=2307;
/***Macro variables that need to be calculated automatically***/
%let FROM='01DEC2022'd;
%let Until='31JUL2023'd;
%let from = %sysfunc(inputn(20&from_yymm.01,yymmdd8.));
%let until = %sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e));
%let from = %sysfunc(inputn(20&from_yymm.01,yymmdd8.));
%let until = %sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e));
I'd suggest:
%let from_date=%sysfunc(putn(%sysfunc(inputn(20&from_yymm.01,yymmdd8.)),date9.));
%let until_date=%sysfunc(putn(%sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e)),date9.));
which will produce macrovars
GLOBAL FROM_DATE 01DEC2022
GLOBAL FROM_YYMM 2212
GLOBAL UNTIL_DATE 31JUL2023
GLOBAL UNTIL_YYMM 2307
I think eliminating the single quotes makes things simpler. FROM_DATE and UNTIL_DATE are human-readable, while allowing this usage in your regular SAS code. Just use double-quotes (which will not mask the value from the macro interpreter) and the trailing letter d.
where date between "&from_date"d and "&to_date"d;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.