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

Hi all --

 

I'm trying to find the best way to accomplish the below code. I want the code to return option C, but in the log, it will return both options B and C. I realize the %if is not able to evaluate a situation with 2 criteria, but what would be the best way to modify the below code to return only "Option C" in this example.

 

Some additional background info on this, I'm using this to run a stored process. Basically, if the results are less than 10,000 I want to return data to the screen, if the data is between 10,000 and 100,000 I will email. If it's over 100,000 I want to stop the stored process and tell the user to adjust their query.

 

%let g_nobs=100000;
%macro run_process;
%if &g_nobs = 0 %then %do;
	%put Option A;
%end;

/*WANT*/
%if 1 < &g_nobs <=10000 %then %do;
	%put Option B;
%end;

%if &g_nobs > 10000 %then %do;
	%put Option C;
%end;

%mend run_process;

%run_process;
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Since 9.4M5 it is possible to use %if in open code, so you can do this:

%let g_nobs=100000;

%if &g_nobs = 0 %then %do;
	%put Option A;
%end;

%if 1 < &g_nobs and &g_nobs <= 10000 %then %do;
	%put Option B;
%end;

%if &g_nobs > 10000 %then %do;
	%put Option C;
%end;

View solution in original post

4 REPLIES 4
r_behata
Barite | Level 11

Use Mutually exclusive conditions :

 

%let g_nobs=100000;

%macro run_process;
	%if &g_nobs = 0 %then
		%do;
			%put Option A;
		%end;

	/*WANT*/
	%if %eval(1 < &g_nobs <=10000) %then
		%do;
			%put Option B;
		%end;
	%else %if %eval(&g_nobs > 10000) %then
		%do;
			%put Option C;
		%end;
%mend run_process;

%run_process;
26         %let g_nobs=100000;
27         
28         %macro run_process;
29         	%if &g_nobs = 0 %then
30         		%do;
31         			%put Option A;
32         		%end;
33         
34         	/*WANT*/
35         	%if %eval(1 < &g_nobs <=10000) %then
36         		%do;
37         			%put Option B;
38         		%end;
39         	%else %if %eval(&g_nobs > 10000) %then
40         		%do;
41         			%put Option C;
42         		%end;
43         %mend run_process;
44         
45         %run_process;
Option B
data_null__
Jade | Level 19

Your syntax for option B is not supported.  This is correct.

 

%if 1 < &g_nobs and &g_nobs <=10000 %then %do;
	%put Option B;
   %end;
Kurt_Bremser
Super User

Since 9.4M5 it is possible to use %if in open code, so you can do this:

%let g_nobs=100000;

%if &g_nobs = 0 %then %do;
	%put Option A;
%end;

%if 1 < &g_nobs and &g_nobs <= 10000 %then %do;
	%put Option B;
%end;

%if &g_nobs > 10000 %then %do;
	%put Option C;
%end;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 4 replies
  • 1874 views
  • 8 likes
  • 4 in conversation