【问题标题】:SAS: sort error (by variable not sorted properly)SAS:排序错误(按变量排序不正确)
【发布时间】:2018-04-30 18:27:30
【问题描述】:

这个问题是我在SAS: Data step view -> error: by variable not sorted properly 的另一个问题的后续;我正在提出一个新问题,因为所需的解决方案略有不同:当我遍历多个输入文件时,其中一个原始文件没有正确排序,我想知道我可以做些什么来让我的程序跳过那个特定的输入文件然后继续?

引用:

我正在使用宏来循环基于名称的文件并提取数据,这在大多数情况下都可以正常工作,但是我有时会遇到

ERROR: BY variables are not properly sorted on data set CQ.CQM_20141113.

其中 CQM_20141113 是我从中提取数据的文件。事实上,我的宏循环通过CQ.CQM_2014:,它一直工作到 20141113。由于这个单一的失败,文件没有被创建。

我正在使用数据步骤视图来“初始化”数据,然后在进一步的步骤中调用数据步骤视图(带有缩短 where 条件的代码示例):

%let taq_ds = cq.cqm_2014:;

data _v_&tables / view=_v_&tables;
     set &taq_ds;
     by sym_root date time_m; *<= added by statement
     format sym_root date time_m;
     where sym_root = &stock;   
run; 

data xtemp2_&stockfiname (keep = sym_root year date iprice);
     retain sym_root year date iprice; 
     set _v_&tables; 
     by sym_root date time_m;

/* some conditions */
run;

当我通过日志文件看到错误并再次运行该文件时,它就可以工作了(有时我需要一些试验)。

我在考虑 proc 排序,但是在使用数据步骤视图时如何做到这一点? 请注意 cqm 文件非常大(这也可能是问题的根源)。 结束引用:

编辑:我尝试了您的代码(并删除了数据步骤视图中的 by 语句),但是我收到了这个错误:

NOTE: Line generated by the macro variable "TAQ_DS".
152         cq.cqm_2013:
                       _
                       22
                       200
ERROR 22-322: Syntax error, expecting one of the following: a name, ;, (, ',', 
              ANSIMISS, AS, CROSS, EXCEPT, FULL, GROUP, HAVING, INNER, 
              INTERSECT, JOIN, LEFT, NATURAL, NOMISS, ORDER, OUTER, RIGHT, 
              UNION, USING, WHERE.  

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of 
      statements.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds



ERROR: File WORK._V_CQM_2013.DATA does not exist.

NOTE: The SAS System stopped processing this step because of errors.
NOTE: SAS set option OBS=0 and will continue to check statements. 
      This might cause NOTE: No observations in data set.
WARNING: The data set WORK.XTEMP2_OXY may be incomplete.  When this step was 
         stopped there were 0 observations and 8 variables.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.00 seconds

【问题讨论】:

    标签: sorting dynamic sas conditional-statements datastep


    【解决方案1】:

    在创建视图时需要by 语句吗?

    如果不是,则从视图中排序到一个临时数据集:

    proc sort data=_v_&tables out=__temp; 
         by sym_root date time_m;
    run;
    
    data xtemp2_&stockfiname (keep = sym_root year date iprice);
         retain sym_root year date iprice; 
         set __temp; 
         by sym_root date time_m;
    
    /* some conditions */
    run;
    

    另一种选择是在PROC SQL 中创建视图并添加排序顺序:

    proc sql noprint;
    create view _v_&tables as
    select <whatever>
       from &taq_ds
       where <clause>
       order by sym_root, date, time_m;
    quit;
    

    【讨论】:

    • 感谢@DomPazz:我认为您的回答更适合我的另一个问题;在这里,我正在寻找一种可能性来告诉我的程序,例如:“运行文件,如果您遇到排序错误(或任何其他错误,如果无法进行排序规范),那么只需跳过此步骤并继续下一个”。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多