Hello
May you please look at the following code and tell what is wrong with it?
The error is
ERROR: All positional parameters must precede keyword parameters.
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(x,branchP);
PROC SQL;
create table outcome_&x. as
select *
from tbl
where branch in (&branchP.)
;
QUIT;
%mend;
%rjoe(x=1,branchP=100);
%rjoe(x=2,branchP=200);
%rjoe(x=3,branchP=300);
%rjoe(x=4,branchP=400);
%rjoe(x=5,branchP=500);
%rjoe(x=6,branchP=100 200 300 400 500);/*It is working well*/
%rjoe(x=6,branchP=100, 200, 300, 400, 500);/*It is not working .why??*/
You have no keyword parameters in your macro definition (only positional ones), but supply keyword parameters in the call. Make up your mind how you want to call your macro.
%rjoe(x=6,branchP=100, 200, 300, 400, 500);
Has a major issue in that you defined the macro with two variables. But since the comma is the macro delimiter in a parameter list you have 4 extra parameters: 200 300 400 500.
Since the code you are using with the IN operator does not require a comma then use
%rjoe(x=6,branchP=100 200 300 400 500);/
The specific error you get comes from the macro parser. From the documentation: Note: You can define an unlimited number of parameters. If both positional and keyword parameters appear in a macro definition, positional parameters must come first.
I added emphasis. Since you had comma delimited items after the other x= and branch = the parser saw positional parameters after the keyword parameters. If you had used:
%rjoe(6,100, 200, 300, 400, 500);
You would have received an error of "more positional parameters found than defined" or similar.
Commas are interpreted as delimiters of the arguments in the call to the macro. The %STR function allows the commas to be treated as text instead of delimeters.
%rjoe(x=6,branchP=%str(100, 200, 300, 400, 500))
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.