简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM