将宏变量传递给proc sql时引号出错

时间:2015-06-08 12:52:25

标签: sas-macro proc-sql

我正在尝试在宏中执行以下操作:

proc sql;

select * from table1 where col1 like 'x%'

quit;


%macro temp(val=x);

proc sql;

select * from table1 where col1 like '&val%'

quit;

%mend;

问题是要解析val的值,它必须是双引号(“”),但sql语句只能用单引号(''),因为它会引发双引号错误:无效的列名。

有任何建议如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

我不认为问题与proc sql或引号有关。 因此,Proc Sql也可以与双引号完美配合。此外,宏变量不会在单引号下解析。

我的试用版:

*1st attempt:* 
%macro test( x=feed);
proc sql;
create table test5 as
select * from files.spiderlist
where host like  "&x%";
quit;
%mend test;

*2nd attempt with || :*  
where host like  ("&x" || '%');

返回"反馈", " feedfetcher",第一次尝试比第二次尝试稍快。

相关问题