☑ This topic is solved.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 09-04-2023 05:02 PM
(530 views)
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;
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let from = %sysfunc(inputn(20&from_yymm.01,yymmdd8.));
%let until = %sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e));
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%let from = %sysfunc(inputn(20&from_yymm.01,yymmdd8.));
%let until = %sysfunc(intnx(month,%sysfunc(inputn(20&until_yymm.01,yymmdd8.)),0,e));
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set
Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets
--------------------------