BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
VSht
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

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');  
--------------------------
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

--------------------------

View solution in original post

2 REPLIES 2
mkeintz
PROC Star

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');  
--------------------------
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

--------------------------
VSht
Obsidian | Level 7

Thank you!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 502 views
  • 1 like
  • 2 in conversation