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*/
%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))
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.