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


I'm getting an error when I run this code:

%let cutoff = 201506;

%let averageperiod = 8;

%let startqtr = %SYSFUNC(intnx('qtr', %input(%put(&cutoff*100+ 01,8.),yymmdd8.), -&averageperiod, 'same'));

%put &startqtr;

the error says...

ERROR: Open code statement recursion detected.

885  %let averageperiod = 8;

886  %let startqtr = %SYSFUNC(intnx('qtr', %input(%put(&cutoff*100+

886! 01,8.),yymmdd8.), -8, 'same'));

ERROR: Open code statement recursion detected.

887  %put &startqtr;

ERROR: Open code statement recursion detected.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why not simplify the code by using a call symput in a data _null_.

%let cutoff = 2015Q06;

%let averageperiod = 8;

data _null_;

     call symput('startqtr',intnx('qtr',input(&cutoff,yyq9.),-&averageperiod, 'same'));

run;


My personal preference is to not put actionable code in macro as it just gets too complicated and difficult to read:  Leave macros for parameters for the overall program, and pieces of code which you don't want to repeat.  Write base SAS to manipulate data.

View solution in original post

4 REPLIES 4
arodriguez
Lapis Lazuli | Level 10

Hi,

the %put function exist? It seems that the error is because the %put, if you run

%let cutoff = 201506;

%let averageperiod = 8;

%let var=%put(&cutoff*100+ 01,8.);

You have the same error

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Why not simplify the code by using a call symput in a data _null_.

%let cutoff = 2015Q06;

%let averageperiod = 8;

data _null_;

     call symput('startqtr',intnx('qtr',input(&cutoff,yyq9.),-&averageperiod, 'same'));

run;


My personal preference is to not put actionable code in macro as it just gets too complicated and difficult to read:  Leave macros for parameters for the overall program, and pieces of code which you don't want to repeat.  Write base SAS to manipulate data.

Kurt_Bremser
Super User

%put and %input are macro statements and not macro functions. %put (or %input) is not allowed within another macro statement.

See SAS(R) 9.2 Macro Language: Reference, paragraph "Solving Open Code Statement Recursion Problems".

I suggest you solve your conversion in a data _null_ step and use call symput to create the macro variable startqtr:

%let cutoff = 201506;

%let averageperiod = 8;

data _null_;

startqtr = intnx('qtr', input(put(&cutoff*100+ 01,8.),yymmdd8.), -&averageperiod, 'same');

call symput('startqtr',put(startqtr,best.));

run;

data_null__
Jade | Level 19

You have several things wrong starting the conversion of YYYYMM to date.  I formatted STARTQTR but you may want to leave it integer(sas date).  Consider the follow

/*
%let cutoff = 201506;
%let averageperiod = 8;
%let startqtr = %SYSFUNC(intnx('qtr', %input(%put(&cutoff*100+ 01,8.),yymmdd8.), -&averageperiod, 'same'));
%put &startqtr;
*/


%let cutoff = 201506;

/*To convert CUTOFF to SAS date you can use YYMMN informat*/
%let cutoffdate = %sysfunc(inputn(&cutoff,yymmn,6));
%put &=cutoffdate;

%let averageperiod = 8;
/*dont use quotes 'qtr' and 'same' are wrong*/
%let startqtr = %SYSFUNC(intnx(qtr, &cutoffdate, -&averageperiod, same),date9);
%put &=startqtr;

32        
/*To convert CUTOFF to SAS date you can use YYMMN informat*/
33        
%let cutoffdate = %sysfunc(inputn(&cutoff,yymmn,6));
34         %put &=cutoffdate;
CUTOFFDATE=20240
35        
36         %let averageperiod = 8;
37         /*dont use quotes 'qtr' and 'same' are wrong*/
38         %let startqtr = %SYSFUNC(intnx(qtr, &cutoffdate, -&averageperiod, same),date9);
39         %put &=startqtr;
STARTQTR=01JUN2013

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1893 views
  • 1 like
  • 5 in conversation