使用like的SQL问题

使用like的SQL问题,sql,sas,Sql,Sas,我正在尝试编写一个宏来搜索列中的文本字符串。我尝试了以下方法来调试我的SAS宏,但它不起作用 %let string = hello Proc sql; Create table abc.&string. as From abc.source Where column like '%'&string.'%'; Quit; 我省略了selectvariables行,因为它不相关 错误消息是 error: invalid date/time/date time constant

我正在尝试编写一个宏来搜索列中的文本字符串。我尝试了以下方法来调试我的SAS宏,但它不起作用

%let string = hello

Proc sql;
Create table abc.&string. as
From abc.source
Where column like '%'&string.'%';
Quit;
我省略了selectvariables行,因为它不相关

错误消息是

error: invalid date/time/date time constant '%' h
我认为它不喜欢我调用已定义字符串的方式。我猜
'%'&string'%'
的语法不正确


知道我做错了什么吗?

你的like子句不起作用,可以在下面试试

    %let string = 'hello' 

       Proc sql;
      Create table cats('abc', &string)  
          as
        From abc.source
       Where column like 
      cats('%', &string, '%') ;
         Quit;

使用
%nrstr
屏蔽宏调用字符(
%
)。这可以放在双引号内,以允许解析字符串宏变量。尾随任意匹配的第二个
%
不需要屏蔽,因为它的后续字符是
,不会触发调用宏的尝试

%let string = an;

proc sql;
  create table an_students as
  select * from sashelp.class
  where name like "%nrstr(%%)&string%";
  ;
或者,只需使用
contains
运算符

  where name contains "&string"

不起作用-它说找不到函数concat,而另一个给出了一个错误,即在贡献表中找不到以下列:helloIt确实将CAT识别为一个现有函数,但后来我得到了与另一个相同的错误,我得到了与CAT相同的错误:我没有找到以下列n贡献表:helloDid您首先将hello放在单个qoutes中。首先QOUTEHello作为%let string='hello'谢谢!这解决了like语句的问题,但是输出表名不再工作-这给了我abc的语法错误。'hello'