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;
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;
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
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;
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;
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!
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.