Hi Team,
Please help me on this.
I have a SAS BASE code.This code contains code for 3 models.I want to have a macro variable in beginning which has parameters to set models for which you want to execute for.
for example if a give call like %run(model1,model2)
it executes just part of code related to model1 and model2.
Please guide me how to go about it.
You will have to post the code and mark the parts that need to be parameterized, then we can give you hints how to go about it.
Hi,,
Here is my requirement.
my script contains code for.
Model1
Model2
Model3
i need a way to run one or more models ast a time..
so my macro calls could be
%run_model(Model1)
%run(Model1,MOdel2)
%run(Model2,Model3)
%run(Model1,Model2,Model3)
Write a macro and use conditional statements to execute the parts you want.
From your description I would have one parameter and pass in the list of models to run.
%macro run(model_list);
%let model_list=%upcase(model_list);
%if %sysfunc(indexw(&model_list,MODEL1)) %then %do;
* code to run model 1 goes here;
%end;
%if %sysfunc(indexw(&model_list,MODEL2)) %then %do;
* code to run model 2 goes here;
%end;
%* add as many models as you want ;
%mend run;
You can then call it with 0,1,2,3,.... models by just listing the model names.
%run(model1)
%run(model1 model2)
Hi,,
Here is my requirement.
my script contains code for.
Model1
Model2
Model3
i need a way to run one or more models ast a time..
so my macro calls could be
%run_model(Model1)
%run(Model1,MOdel2)
%run(Model2,Model3)
%run(Model1,Model2,Model3)
Don't use commas in the macro call. That implies multiple paramaters. Use spaces so that the list of models is passed as the value to a single parameter.
hi,Below is log which is getting generated,the macro call is unable to execute code as %IF condition is comming false.Please Help me on it.Thanks!
options mprint mlogic;
%runmodels(alpha beta);
MLOGIC(RUNMODELS): Beginning execution.
MLOGIC(RUNMODELS): Parameter MODEL_LIST has value alpha beta
MLOGIC(RUNMODELS): %LET (variable name is MODEL_LIST)
MLOGIC(RUNMODELS): %IF condition %sysfunc(indexw(&model_list,alpha)) is FALSE
MLOGIC(RUNMODELS): %IF condition %sysfunc(indexw(&model_list,beta)) is FALSE
MLOGIC(RUNMODELS): Ending execution.
Your log messages do not show what value the %LET statement assigned to the MODEL_LIST variable, but if it was like the macro I posted before it would have converted it to upper case to allow the testing to work when users passed in lowercase or mixed case values.
But the %IF conditions that are resulting in false are checking for lowercase alpha and beta.
Either change the %LET or change the INDEXW() tests.
Hi I got it working..I have another question related to it.
Now below is my macro
%macro run(model_list);
%if %sysfunc(indexw(&model_list,ALPHA)) %then %do;
%if %sysfunc(indexw(&model_list,BETA)) %then %do;
--
--
--;
%mend run;
and then the macro call
%run(ALPHA BETA)
so i have to run the macro defination first..scroll down the entire script and then call macro..
is there somewhy i can do both these steps of running macro defination and call in one step?
TIA. 🙂
SO basically is there a way i can run macro defination and macro call together.?
I don't understand the question. If you have a program file then just run the program.
%macro run(list);
....
%mend run;;
%run(alpha);
%run(beta);
If you want to maintain the macro defintion and the program that use it as two different source files then just add a %INCLUDE to include the macro definition when needed.
%include 'run.sas' ;
%run(apha);
%run(beta);
... .more code ...
%run(beta alpha);
Note that once the macro is compiled you do not need to re-run the definition unless you restart SAS or delete the compiled version somehow.
You could also look into creating your own autocall library. With AUTOCALL SAS will load the macro definition the first time you try to run it so you don't have to add %include statements for every macro you want to call.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.