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 open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.