%macro psql(dsname= ,x=);
proc sql;
select Name ,sex, Age from &dsname order by &x;
quit;
%mend;
*calling ;
;
%psql(dsname=sashelp.class,%str(x=sex, x=age desc));
Since you only need to mask the comma, the %STR function is sufficient:
%psql(dsname=sashelp.class,x=%str(sex,age desc));
Please try the below call
%psql(dsname=sashelp.class,x=%nrstr(sex, age desc));
Since you only need to mask the comma, the %STR function is sufficient:
%psql(dsname=sashelp.class,x=%str(sex,age desc));
You need to use a WHERE condition in the SQL select.
Start by creating the necessary SQL code without macro coding, once it works, you can make it dynamic.
Agreeing with @Kurt_Bremser . You can't write macros and expect them to work until you have working code without macros.
So, here is your code when run as
%psql(dsname=sashelp.class,x=%str(sex ='F',Age desc))
&DSNAME is replaced by sashelp.class and &X is replaced by %str(sex='F',age desc), producing this incorrect SQL code
proc sql;
select Name ,sex, Age from sashelp.class order by sex='F',Age desc;
quit;
Can you see why this SQL code doesn't work? So first, you have to write correct SQL code without macros and without macro variables, and fix the problems in the code immediately above. Show us correct SQL code that works, without macros and without macro variables, for this situation.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.