2015-06-08 38 views
0

我试图做宏如下:误差与报价,同时通过宏观变量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语句只能使用单引号(''),因为它会用双引号引起错误:无效的列名称。

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

回答

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" || '%'); 

都返回 “资讯提供ly”, “Feedfetcher会”,与第一次的尝试比第二次尝试稍快。

+0

使用双引号直接表达的proc sql语句不起作用:像select * from table1其中col1类似于“x%”或infact col1 =“x”,所有引发同样的错误:列名称无效。 – user2542275

+0

请看看类似的问题:http://stackoverflow.com/questions/27288623/sas-proc-sql-inside-macro – yukclam9

+0

请检查编辑答案 – yukclam9