BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

I am trying to learn keyword parameters in macro.

May someone explain and fix the code 

 

Data tbl;
input ID  branch;
cards;
1 100
2 100
3 200
4 300
5 400
6 500
7 500
8 500
9 500
10 500
;
run;
%macro rjoe(branchP=100);
PROC SQL;
	create table outcome as
	select *	   
	from tbl
	where branch in (&branchP.)
;
QUIT;
proc print noobs;run;
%mend;
%rjoe;
%rjoe(branchP=200);
%rjoe(branchP=300);
%rjoe(branchP>=0);/*No working*/
1 REPLY 1
PaigeMiller
Diamond | Level 26

 

%rjoe(branchP>=0);/*No working*/


 

There is no such thing as calling a macro where you insert the > sign where the equal sign ought to go. Macro arguments can't work this way, you must have the macro variable name followed by an equal sign. Do not try to MIX and MATCH data step syntax in your macro call.

 

Also, when your macro runs, it must produce valid working SAS code.

 

So, when your macro runs, it seems like you want it to produce

 

 

where branch in (>=0)

which is not valid working SAS code.

 

 

If you want the macro calls to produce legal SAS code, something like this (and there are other ways to accomplish the same)

 

%macro rjoe(branchP=);
PROC SQL;
	create table outcome as
	select *	   
	from tbl
	where branch &branchP
;
QUIT;
proc print noobs;run;
%mend;
%rjoe(branchP = %str(eq 100))
%rjoe(branchP = %str(eq 200))
%rjoe(branchP = %str(eq 300))
%rjoe(branchP = %str(ge 0))

 

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1369 views
  • 1 like
  • 2 in conversation