BookmarkSubscribeRSS Feed
cau83
Pyrite | Level 9

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.

3 REPLIES 3
AncaTilea
Pyrite | Level 9

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.

cau83
Pyrite | Level 9

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.

cau83
Pyrite | Level 9

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 3 replies
  • 1140 views
  • 3 likes
  • 2 in conversation