Search code examples
sassas-macro

SAS Macro, passing value as string to where clause


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.


Solution

  • 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);