Hi,
Some time ago I created a program calculating various dates and then putting them into macros. It worked. Now it does not work. It creates a table, but does not create macro variables. I also noticed that when I run it as a data step with preceding %let assignments it works. As soon as I put it into a macro it does not work.
A shortened version of the code is below or the full program is attached.
Any feedback is much appreciated.
%macro rpt_time(Multiplier=);
DATA periods;
*------------------------------------------------------------------------------------;
* From TODAY();
format end_dt FYstart_dt pr_end_dt ddmmyy10.;
today = today()-30.5*&Multiplier;
end_dt = intnx('month',today-30.5*2,0,"E");
pr_end_dt = intnx('month',today-30.5*2 - 365.25,0,"E");
* PREP;
year = year(today-30.5*2);
end_monyy = put(today-30.5*2,monyy.);
mth = month(today)-2;
*------------------------------------------------------------------------------------;
* MONTH;
current_mth = put(month(today)-2,z2.); /* Current month number - text */
* PERIOD;
format period_no $2.;
if mth>6 then period_no=put(mth-6,2.); /* Financial period (month) */
if mth<7 then period_no=put(mth+6,2.);
* FIN YEAR;
if mth>6 then do; /* Fin Year: -start- and -end- years */
FYstart = year;
FYend = year+1;
end;
else if mth<7 then do;
FYstart = year-1;
FYend = year;
end;
*------------------------------------------------------------------------------------;
* Utilities for naming;
* YEAR;
FYend_2 = substr(put(FYend,z4.),3,2);
fy_prev1 = put(FYend_2-1,z2.);
fy_prev2 = put(FYend_2-2,z2.);
fy_prev3 = put(FYend_2-3,z2.);
* FIN YEAR Start Date = 1JulYY;
FYstart_dt = mdy(7,1,FYstart_2);
* -----------------------------------------------------------------------------------;
*Macro names;
call symputx('current_mth',current_mth); /* Current calendar month - number */ /* supposedly for DiLM, could not find ????????? */
call symputx('period_no',period_no); /* Current financial period (variable -period- in the dataset) - number */
call symputx('end_dt',end_dt); /* To subset data in Macros: End of Report period - date numeric */
call symputx('year',year);
call symputx('FY6',year);
call symputx('fy_curr',FYend_2); /* FY value for CHBOI data assembly - 2-char */ /* end*/
call symputx('fy_prev1',fy_prev1); /* FY value for CHBOI data assembly - 2-char */
call symputx('fy_prev2',fy_prev2); /* FY value for CHBOI data assembly - 2-char */
call symputx('fy_prev3',fy_prev3); /* FY value for CHBOI data assembly - 2-char */
call symputx('FYstart_dt',FYstart_dt); /* Date value for the beginning of FYear - date numeric */
call symputx('pr_end_dt',pr_end_dt); /* Last year date value for the end of Report period - date numeric - for YTD DiLM */
RUN;
%mend;
This is a SCOPE issue. Your call symputx statement are creating macrovars local to the RPT_TIME macro. They are not creating global macrovars, which is what your subsequent %PUT statements are searching for.
So if you need the macrovars to be global, insert the additional argument ,"G" in each call symputx statement, as in:
call symputx('quarter_no',quarter_no,'G');
This is a SCOPE issue. Your call symputx statement are creating macrovars local to the RPT_TIME macro. They are not creating global macrovars, which is what your subsequent %PUT statements are searching for.
So if you need the macrovars to be global, insert the additional argument ,"G" in each call symputx statement, as in:
call symputx('quarter_no',quarter_no,'G');
Thank you!
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.