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))
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.