Hello,
I have a data set containing X12 specs for about 150 series. I am trying to build a macro do loop that will assign new values to macro variables for the X12 specs as the do loop goes through the series. I keep having issues with how the macro variables used in the X12 speca are resolving.
For the record I have tried:
= "®";
= (®);
=("®");
%macro doauto; %do i=1 %to &numauto; data am; set qspecauto; if ct = &i; call symput ('reg',strip(reg_predefined)); call symput ('acctt', strip(acctt)); run; data qnsause; set qnsa; if strip(acctt)= "&acctt"; /* This resolves fine*/ run; proc x12 data = QNSAuse date = period interval = qtr outstat = X12Sum; var NSA; id; regression predefined = ®/*<----- This has issues*/ automdl; run; %end; %mend doauto; %doauto;
The error in the log is:
MPRINT(DOAUTO): proc x12 data = QNSAuse date = period interval = qtr outstat = X12Sum;
MPRINT(DOAUTO): var NSA;
MPRINT(DOAUTO): id;
SYMBOLGEN: Macro variable REG resolves to td easter
NOTE: Line generated by the invoked macro "DOAUTO".
2 var NSA; id; regression predefined = ® automdl; run;
-
79
ERROR 79-322: Expecting a (.
NOTE: Line generated by the invoked macro "DOAUTO".
2 var NSA; id; regression predefined = ® automdl; run;
-
76
ERROR 76-322: Syntax error, statement will be ignored.
MPRINT(DOAUTO): regression predefined = td easter;
MPRINT(DOAUTO): automdl;
MPRINT(DOAUTO): run;
I tried this after I posted and was just coming back to update my question.
I ran just the proc x12 with hardcoded ® ( td easter ) I did get the same error. Ultimately I'm using someone elses old X12 specs to run seasonal adjustment this year. So, instead of using automdl I decided to just specify the arima model that was the final model used last year. The code works this way even in the macro.
I can't say why because I don't know enough about X12 but maybe there's an issue with supplying a regression spec if you select automdl or there's an issue with the order in which I specified. Whaterv the issue, I've found a solution that works for me.
Thanks for both of your quick replies!
Thanks,
Alice
What does your X12 code look like without macro code and the variables hard coded in? Does that work without errors?
Along with what @Reeza has asked, what does reg contain? Does it potentially contain parentheses?
Issues with macro vars resolving when used in proc X12 specs
seems to work ok for me
inspired by
https://goo.gl/BCUnos
https://communities.sas.com/t5/SAS-Procedures/Issues-with-macro-vars-resolving-when-used-in-proc-X12-specs/m-p/343462
HAVE
====
Up to 40 obs WORK.HAVE1 total obs=19
Obs CT REG_PREDEFINED
1 1 Alfred
2 2 Alice
3 3 Barbara
4 4 Carol
5 5 Henry
6 6 James
Up to 40 obs from have2 total obs=57
Obs NSA ACCTT SALES
1 14 Alfred 69.0 Model these
2 2 Alfred 57.0
3 39 Alfred 61.0
4 13 Alice 56.5 Model these
5 70 Alice 92.0
6 81 Alice 12.0
7 13 Barbara 65.3 Model these
8 36 Barbara 49.0
9 51 Barbara 30.0
WANT (Three datasets WORK.ALICE WORK.ALFRED WORK.BARBARA
========================================================
ALICE
Up to 40 obs from ALICE total obs=1
Obs _MODEL_ _DEPVAR_ INTERCEPT SALES
1 Alice NSA 65.1136 -0.19527
ALFRED
Up to 40 obs from ALFRED total obs=1
Obs _MODEL_ _DEPVAR_ INTERCEPT SALES
1 Alfred NSA -7.26786 0.41071
BARBARA
Up to 40 obs from BARBARA total obs=1
Obs _MODEL_ _DEPVAR_ INTERCEPT SALES
1 Barbara NSA 84.7342 -1.06863
WORKING CODE
============
do i=1 to 3;
dosubl
set have1;
if ct=&ct;
call symputx ("reg",reg_predefined);
call symputx ("acctt", reg_predefined);
set have2;
if acctt= "&acctt";
proc reg data=qnsause outest = ®
®: model nsa=sales ;
run;quit;
FULL SOLUTION
=============
* _ _ _
_ __ ___ __ _| | _____ __| | __ _| |_ __ _
| '_ ` _ \ / _` | |/ / _ \_____ / _` |/ _` | __/ _` |
| | | | | | (_| | < __/_____| (_| | (_| | || (_| |
|_| |_| |_|\__,_|_|\_\___| \__,_|\__,_|\__\__,_|
;
proc datasets lib=work kill;
run;quit;
data have1;
retain ct 0;
length ct 8 reg_predefined $8;
set sashelp.class(keep=name rename=name=reg_predefined);
ct=_n_;
run;quit;
data have2;
length nsa 8 acctt $8;
set sashelp.class(keep=name age height
rename=(age=nsa name=acctt height=sales));
output;
nsa=int(100*uniform(5731));sales=int(100*uniform(5732));output;
nsa=int(100*uniform(5733));sales=int(100*uniform(5734));output;
run;quit;
* _ _ _
___ ___ | |_ _| |_(_) ___ _ __
/ __|/ _ \| | | | | __| |/ _ \| '_ \
\__ \ (_) | | |_| | |_| | (_) | | | |
|___/\___/|_|\__,_|\__|_|\___/|_| |_|
;
%symdel reg acctt/nowarn;
data _null_;
do i=1 to 3;
call symputx('ct',put(i,3.));
rc=dosubl('
data qspecauto;
set have1;
if ct=&ct;
call symputx ("reg",reg_predefined);
call symputx ("acctt", reg_predefined);
run;quit;
data qnsause;
set have2;
if acctt= "&acctt";
run;quit;
proc reg data=qnsause outest = ®(keep=_model_ _depvar_ intercept sales) ;
®: model nsa=sales ;
run;quit;
');
end;
run;quit;
1872 %symdel reg acctt/nowarn;
1873 data _null_;
1874 do i=1 to 3;
1875 call symputx('ct',put(i,3.));
1876 rc=dosubl('
1877 data qspecauto;
1878 set have1;
1879 if ct=&ct;
1880 call symputx ("reg",reg_predefined);
1881 call symputx ("acctt", reg_predefined);
1882 run;quit;
1883 data qnsause;
1884 set have2;
1885 if acctt= "&acctt";
1886 run;quit;
1887 proc reg data=qnsause outest = ®(keep=_model_ _depvar_ intercept sales)
1888 ®: model nsa=sales ;
1889 run;quit;
1890 ');
1891 end;
1892 run;
SYMBOLGEN: Macro variable CT resolves to 1
NOTE: There were 19 observations read from the data set WORK.HAVE1.
NOTE: The data set WORK.QSPECAUTO has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1028.06k
OS Memory 20468.00k
Timestamp 03/22/2017 07:05:41 PM
Step Count 464 Switch Count 0
SYMBOLGEN: Macro variable ACCTT resolves to Alfred
NOTE: There were 57 observations read from the data set WORK.HAVE2.
NOTE: The data set WORK.QNSAUSE has 3 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 1028.06k
OS Memory 20468.00k
Timestamp 03/22/2017 07:05:41 PM
Step Count 464 Switch Count 0
SYMBOLGEN: Macro variable REG resolves to Alfred
SYMBOLGEN: Macro variable REG resolves to Alfred
NOTE: The data set WORK.ALFRED has 1 observations and 4 variables.
NOTE: PROCEDURE REG used (Total process time):
real time 0.09 seconds
user cpu time 0.00 seconds
system cpu time 0.04 seconds
memory 2039.46k
OS Memory 20980.00k
Timestamp 03/22/2017 07:05:41 PM
Step Count 464 Switch Count 1
I tried this after I posted and was just coming back to update my question.
I ran just the proc x12 with hardcoded ® ( td easter ) I did get the same error. Ultimately I'm using someone elses old X12 specs to run seasonal adjustment this year. So, instead of using automdl I decided to just specify the arima model that was the final model used last year. The code works this way even in the macro.
I can't say why because I don't know enough about X12 but maybe there's an issue with supplying a regression spec if you select automdl or there's an issue with the order in which I specified. Whaterv the issue, I've found a solution that works for me.
Thanks for both of your quick replies!
Thanks,
Alice
Even more info on the solution. The value of ® was "td easter." This is an acceptable spec for regression inder the aictest if you are using Census' Win X-13. I was interpreting that as being an acceptable spec for SAS proc X13 for predefined regression. However, the X13 manual from SAS clearly states https://support.sas.com/documentation/onlinedoc/ets/141/x13.pdf
"The predefined regression variables, EASTER, LABOR, SCEASTER, SINCOS, TDSTOCK, and THANK, require extra parameters."
"regression predefined=easter(7) easter(14);"
This was the real problem. I needed to be more specific about which easter to use.
@alicek Thanks for coming back and posting the answer 🙂
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.