My code is for testing forecasting models on a holdout sample in order to test and do forecast value added analysis so that we can do model selection. Using PROC ESM, we have 8 model choices and then we also need to perform a 2 week forecast for each of the 6 weeks (so I have a 1 to 8 loop for the model choices and a 1 to 6 loop for the weeks). Here's the code:
%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_;
by queue_nm lob;
id date interval=day zeromiss=left;
forecast effort/ model=&modelspec;
run;
%end;
%end;
%mend;
%modeltest(Dept=OSS,holdoutweeks=6);
I get an unnecessary warning (or, it is necessary and I do not yet realize the impact it could have, hence my question) on the line where I ID'd a problem. I want &modelspec to step through the 8 models each time, so be equal to &modelname1 then &modelname2 and so on. I'll selectively copy and paste some lines from the log to show the warning and that (I believe) it is ultimately working anyway:
MLOGIC(MODELTEST): %LET (variable name is MODELSPEC)
WARNING: Apparent symbolic reference MODELNAME not resolved.
SYMBOLGEN: Macro variable J resolves to 1
SYMBOLGEN: Macro variable MODELSPEC resolves to &modelname1
It appears that SAS is evaluating "&modelname" first before evaluating the entire "&modelname&j". Should I be concerned about this warning and how can I get rid of it? Is there a different way to do the specification?
I am also having a problem with naming the output data sets, but I posted that separately here: https://communities.sas.com/thread/48073 . thanks for any help/ideas.
-Chris
try changing %let modelspec=&modelname&j;
to
%let modelspec=&&modelname&j;
try changing %let modelspec=&modelname&j;
to
%let modelspec=&&modelname&j;
Linlin, that worked thanks.
Now I get in the log:
SYMBOLGEN: && resolves to &.
Just curious now: So the double ampersand tells SAS to... what exactly? How does this work?
first time resolves
&&modelname&j to &modelname1
second time resolves
&modelname1 to simple.
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.