BookmarkSubscribeRSS Feed
changxuosu
Quartz | Level 8

Hi Guys,

 

I need your wisdom. Here is my question:

 

I'm currently doing a forecast project. I have completed model fitting and I want to do sensitivity analysis, which means I want to marginally change each variable used in the final model and see how the model performs when variables change.

 

I'd like to write a macro and a loop to loop through each variable I used in the model, so that I can set each variable to change by a certain amount, and also output the model output for each variable changed.

 

My problem is that, I have like 10 forecast projects. It's tedious to manually input 10 lists of final variables when writing the SAS codes.

When I was doing model fitting (using logistic regression), I saved model output using "outmodel=yy" option as below

 

PROC logistic DATA=xx descending outmodel=yy;

 

MODEL outcome= &var_list;

run;

 

So my question is, is there any convenient way to extract variable list from yy ? If so, I'm saved from manually copy and paste 10 variable lists.

 

THanks in advance!

 

 

1 REPLY 1
ballardw
Super User

@changxuosu wrote:

Hi Guys,

 

I need your wisdom. Here is my question:

 

I'm currently doing a forecast project. I have completed model fitting and I want to do sensitivity analysis, which means I want to marginally change each variable used in the final model and see how the model performs when variables change.

 

I'd like to write a macro and a loop to loop through each variable I used in the model, so that I can set each variable to change by a certain amount, and also output the model output for each variable changed.

 

My problem is that, I have like 10 forecast projects. It's tedious to manually input 10 lists of final variables when writing the SAS codes.

When I was doing model fitting (using logistic regression), I saved model output using "outmodel=yy" option as below

 

PROC logistic DATA=xx descending outmodel=yy;

 

MODEL outcome= &var_list;

run;

 

So my question is, is there any convenient way to extract variable list from yy ? If so, I'm saved from manually copy and paste 10 variable lists.

 

THanks in advance!

 

 


It might help to show the LOOP code you are proposing or attempting to use. I would typically look at the loop index to modify output data set names or perhaps macro reference variables.

 

I'm not sure how you would expect to get var_list fom yy as your variable list would require spaces and total text likely would exceed the length of a possibly output data set name.

 

If you have multiple var_lists defined perhaps you are looking for something along these lines:

%let a1 =var1 var2 var3;
%let a2 = var2 var3 var4;

%macro dummy (loops=);

%do i= 1 %to &loops.;
   %put Loop &i. outset name= a&i. varlist= &&a&i.;
%end;
%mend;

%dummy(loops=2);

The &&a&i is a sometimes tricky to follow resolution of macro variables. In effect the && says hold the next value for a moment and see if there is a following macro value, if so append it to the held value and then resolve the resulting macro variable. That is not particularly precise but works for this simple and moderately robust structure. You do not want to call with a value of &i outside of the lists A1 A2 etc previous defined.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 782 views
  • 0 likes
  • 2 in conversation