SAS 宏,将值作为字符串传递给 where 子句 [英] SAS Macro, passing value as string to where clause

查看:60
本文介绍了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 子句,并且宏参数是作为位置提供的(而不是名称=值对).请尝试以下操作:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆