SAS宏,将值作为字符串传递给where子句 [英] SAS Macro, passing value as string to where clause
本文介绍了SAS宏,将值作为字符串传递给where子句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面有一个 SAS 宏不起作用 --- 此代码段不返回任何值,因为 where 语句不起作用.有人有想法么?我尝试添加 %str,但也没有用.
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);
谢谢.
推荐答案
宏变量不会用单引号解析.您还缺少 FROM 子句,并且宏参数被提供为位置(而不是 name=value 对).请尝试以下操作:
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);
这篇关于SAS宏,将值作为字符串传递给where子句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文