3
votes

I have a SAS macro below that is not working--- this snippet returns no values because the where statement doesn't work. Anyone have any ideas? I tried adding %str but that didn't work either.

%macro refreshments(beverage_type=);

proc sql;
select

*

where drink_type = '&beverage_type.'
;
quit;

%mend

%refreshments(Sprite);

Thanks.

1
Your SQL is missing a 'from' clause. You need to specify the name of the table you want to query.user667489
In future, if you have difficulties getting a macro working, try removing the macro code and running it as regular SAS code. Once that is working, add the macro code back in.Robert Penridge

1 Answers

4
votes

Macro variables will not resolve in single quotes. You are also missing the FROM clause, and the macro parameter was being provided as positional (instead of name=value pair). Try the following:

%macro refreshments(beverage_type=);
  proc sql;
  select * 
    from YOURTABLE
    where drink_type = "&beverage_type";
%mend;

%refreshments(beverage_type=Sprite);