BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Tom
Super User Tom
Super User

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.

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 16. 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
  • 2 replies
  • 375 views
  • 2 likes
  • 3 in conversation