Hi,
I have a prompt with static list. When I run it creates the following variables:
%LET Selected_Scenarios_count = 3;
%LET Selected_Scenarios0 = 3;
%LET Selected_Scenarios = Base;
%LET Selected_Scenarios3 = Down;
%LET Selected_Scenarios2 = Up;
%LET Selected_Scenarios1 = Base;
I am trying to execute a part of the code only for the Up and Down scenarios. However it runs for all the scenarios. Moreover it does not do the calculation. I am also sharing the input and output data with only 100 rows. My goal is to have only two additional columns with "Naming_Up" and "Naming_Down" calculated.
%macro my_sample();
data WORK.my_output;
set WORK.my_source;
%do h=1 %to &Selected_Scenarios_count.;
if &&selected_scenarios&h.. in('Up','Down') then Naming_&&selected_scenarios&h..=field1*field2;
%end;
run;
%mend my_sample;
%my_sample();
Hi @sas_user_null Perhaps you after this?
%LET Selected_Scenarios_count = 3;
%LET Selected_Scenarios0 = 3;
%LET Selected_Scenarios = Base;
%LET Selected_Scenarios3 = Down;
%LET Selected_Scenarios2 = Up;
%LET Selected_Scenarios1 = Base;
options minoperator;
%macro my_sample()/mindelimiter=',';
%do h=1 %to &Selected_Scenarios_count.;
%if &&selected_scenarios&h.. in(Up,Down) %then %do;
Naming_&&selected_scenarios&h..=field1*field2;
%end;
%end;
%mend my_sample;
%my_sample();
Now, you can call the macro like this
data WORK.my_output;
set WORK.my_source;
%my_sample();
run;
Hi @sas_user_null Perhaps you after this?
%LET Selected_Scenarios_count = 3;
%LET Selected_Scenarios0 = 3;
%LET Selected_Scenarios = Base;
%LET Selected_Scenarios3 = Down;
%LET Selected_Scenarios2 = Up;
%LET Selected_Scenarios1 = Base;
options minoperator;
%macro my_sample()/mindelimiter=',';
%do h=1 %to &Selected_Scenarios_count.;
%if &&selected_scenarios&h.. in(Up,Down) %then %do;
Naming_&&selected_scenarios&h..=field1*field2;
%end;
%end;
%mend my_sample;
%my_sample();
Now, you can call the macro like this
data WORK.my_output;
set WORK.my_source;
%my_sample();
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.