Hello,
Let's say that the following situation :
User define 2 macro variables : business and private (using %let statement ).
I want to create conditions as following:
If macro variable business>=1 then need to do some actions (see the code below).....
If macro variable private>=1 then need to do some actions (see the code below).....
What is the way to do it please?
Is there is another way or just the way I wrote?
%let business=2;
%let private=0;
%macro RRR;
%IF &business.>=1 %then %do;
proc sql;
create table tbl1 as
select make,
sum(invoice) as invoice
from sashelp.cars
where type='Sports'
group by make
;
quit;
proc sql;
create table class_M as
select *
from sashelp.class
where sex='M'
;
quit;
%End;
%IF &private.>=1 %then %do;
proc sql;
create table class_F as
select *
from sashelp.class
where sex='F' and weight>=80
;
quit;
proc sql;
create table class_age_le12 as
select *
from sashelp.class
where age<=12
;
quit;
%End;
%mend RRR;
%RRR;
If you are running a current version of SAS you can have the simple %IF/%THEN/%DO/%END blocks you have in open code without the need to define and call a macro.
The first line under %MACRO RRR;
IF &business>=1 then do;
IF statements can only be in a DATA step. This is not in a DATA step and won't work.
However, this does not have to be in a DATA step
%if &business>=1 %then %do;
and it needs to end with %END; and not END;
So you need to change this throughout your code.
If you are running a current version of SAS you can have the simple %IF/%THEN/%DO/%END blocks you have in open code without the need to define and call a macro.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.
Ready to level-up your skills? Choose your own adventure.