SAS:排序错误(按变量排序不正确)

SAS: sort error (by variable not sorted properly)

这个问题是我在这里遇到的另一个问题的跟进 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。由于这个单一的失败,文件没有被创建。

我正在使用数据步骤视图来 "initialize" 数据,然后在进一步的步骤中调用数据步骤视图(带有缩短 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;

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

我正在考虑过程排序,但是在使用数据步骤视图时如何做到这一点? 请注意 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

创建视图时需要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;