BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sas_user_null
Calcite | Level 5

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();

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

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_user_null
Calcite | Level 5
Magic!!!

Thank you very much for your help. Works perfect!!!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 602 views
  • 0 likes
  • 2 in conversation