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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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