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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: