【问题标题】:SAS Syntax Expecting a SELECT需要 SELECT 的 SAS 语法
【发布时间】:2019-04-23 10:32:11
【问题描述】:

我不确定如何在 SAS 中更正我的 proc sql 中的语法。我的代码如下所示:

proc sql;
    create table HI
    as select [columns]
from [table]
where column1 not in ('..', '..', '..') /*This has no errors*/
AND column2 in ('...', '...', '...') /*This has no errors*/
AND column3 in (('...','...','...',.......)
    or column3 like ('J%')) /*This AND statement gives the errors*/

第一个错误是它期待一个 SELECT 并在第 3 列的条件下划线了第一个“...”。 (错误 79-322)

下一个错误出现在 OR 语句之前的第 3 列条件的末尾。它说它期待以下之一:带引号的字符串、!、!!、&、*、**、+、'、'、-、/、、=、>、> =, ?,.....(错误 22-322)

然后还有两个错误表示符号无法识别,另一个错误表示该语句将被忽略。 --但我认为如果其他人得到纠正,这些都会纠正。

任何帮助表示赞赏:)

【问题讨论】:

    标签: syntax sas quotes proc-sql where-in


    【解决方案1】:

    为 column3 条件添加一对括号 像这样

    AND (column3 in (('...','...','...',.......)
    or column3 like ('J%'))) /*This AND statement gives the errors*/
    

    【讨论】:

      【解决方案2】:

      使用查找运算符

      AND column3 in (('...','...','...',.......)
      or (find(column3,J)>0 and substr(column3,1,1)='J') /*Making sure first char is J*/
      

      【讨论】:

      • @Kiran,我很抱歉,是的,它有效..不知何故我使用了错误的语法
      【解决方案3】:

      把最后两行改成

       AND (column3 in ('...','...','...',.......)
      or column3 like ('J%')) 
      
      /* example*/
       proc sql;
      create table HI
      as select *
       from sashelp.cars
       where make not in ('Acura', 'Audi') /*This has no errors*/
        AND Type in ('SEDAN', "Sports") /*This has no errors*/
       AND (Origin in ('Asia','Europe')
        or Origin like ('U%')) ;
      

      【讨论】:

        猜你喜欢
        • 2021-04-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-11-07
        • 1970-01-01
        • 1970-01-01
        • 2023-03-12
        相关资源
        最近更新 更多