I have a related post here with a separate question about a warning SAS gives: https://communities.sas.com/message/175096#175096
In the code below, on the line I've marked, there are two output data sets that are name using the values of 3 macro variables. I am looping through each forecasting series 48 times (6 different time periods on each of 8 different models).
%macro modeltest(Dept=,holdoutweeks=);
%let modelname1=simple;
%let modelname2=double;
%let modelname3=linear;
%let modelname4=damptrend;
%let modelname5=addseasonal;
%let modelname6=multseasonal;
%let modelname7=winters;
%let modelname8=addwinters;
%do J = 1 %to 2; **loops through the 8 different model choices and does the 6 weeks of forecasting for each**;
%let modelspec=&modelname&j; (*********THE PROBLEM OCCURS HERE********)
%DO I = 1 %TO 1;
%let backpd=%eval((&holdoutweeks+1)*7 - (&i*7)); **backpd = # of days to go back but divided by i so it loops through one week at a time**;
proc esm data=&Dept back=&BackPd lead=14 seasonality=7 nooutall outfor=fcast_&Dept._&i._&modelspec outstat=metrics_&Dept._&i._&modelspec out=_null_; (*****THE PROBLEM IS HERE*****)
by queue_nm lob;
id date interval=day zeromiss=left;
forecast effort/ model=&modelspec;
run;
%end;
%end;
%mend;
%modeltest(Dept=OSS,holdoutweeks=6);
The current specification works, producing the following in the log:
MPRINT(MODELTEST): proc esm data=OSS back=42 lead=14 seasonality=7 nooutall outfor=fcast_OSS_1_simple outstat=metrics_OSS_1_simple out=_null_;
However, I wanted to switch the order of &i and &modelspec so that the outfor dataset in this instance is "fcast_OSS_simple_1". But when I switch it around, using this (outfor=fcast_&Dept._&modelspec._&i), I get errors in the log that I'll selectively paste here:
WARNING: Apparent symbolic reference MODELNAME2_1 not resolved.
NOTE 138-205: Line generated by the macro variable "I".
fcast_OSS_&modelname2_1
ERROR 22-322: Syntax error, expecting one of the following: ;, (, BACK, DATA, LEAD, MAXERROR, NOOUTALL, OUT, OUTCOMPONENT, OUTEST,
OUTFOR, OUTPROCINFO, OUTSTAT, OUTSUM, PLOT, PRINT, PRINTDETAILS, SEASONALITY, SORTNAMES, STARTSUM.
WARNING: Apparent symbolic reference MODELNAME2_1 not resolved.
SYMBOLGEN: Macro variable DEPT resolves to OSS
SYMBOLGEN: Macro variable MODELSPEC resolves to &modelname2
SYMBOLGEN: Macro variable I resolves to 1
NOTE: Line generated by the macro variable "I".
fcast_OSS_&modelname2_1
ERROR 200-322: The symbol is not recognized and will be ignored.
Of course, I can just live with the alternate name (ultimately I'll be appending them all together anyway). I'd like an explanation for learning purposes-- a solution would be nice but not necessary.
In your code would you please try the following:
(see my red markings)
%macro modeltest(Dept=,holdoutweeks=);
%let modelname1=simple;
%let modelname2=double;
%let modelname3=linear;
%let modelname4=damptrend;
%let modelname5=addseasonal;
%let modelname6=multseasonal;
%let modelname7=winters;
%let modelname8=addwinters;
%do J = 1 %to 2; **loops through the 8 different model choices and does the 6 weeks of forecasting for each**;
%let modelspec=&&modelname&j; (*********THE PROBLEM OCCURS HERE********)
%DO I = 1 %TO 1;
%let backpd=%eval((&holdoutweeks+1)*7 - (&i*7)); **backpd = # of days to go back but divided by i so it loops through one week at a time**;
proc esm data=&Dept back=&BackPd lead=14 seasonality=7 nooutall outfor=fcast_&Dept._&i._&modelspec outstat=metrics_&Dept._&i._&modelspec out=_null_; (*****THE PROBLEM IS HERE*****)
by queue_nm lob;
id date interval=day zeromiss=left;
forecast effort/ model=&modelspec;
run;
%end;
%end;
%mend;
%modeltest(Dept=OSS,holdoutweeks=6);
PS: has a nice, straightforward paper that explains the use of double ampersand.
This was the answer to my other question (where I was receiving a warning w/o the &&), but it does not solve this issue.
I will check out the paper to which you linked.
I ended up finding a more compact method for assigning the model name after I did this post (I noticed a separate thread here: https://communities.sas.com/ideas/1084). I now use this specification and without the &modelname reference the datasets no longer have an issue-- still do not understand why it was a problem in the first place.
%let models= simple/double/linear/damptrend/addseasonal/multseasonal/winters/addwinters;
%do j=1 %to 8;
%let modelspec=%scan(&models,&j);
outfor=fcast_&Dept._&modelspec._&i
Thanks.
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 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.