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.
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.
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
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.
%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;
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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.