SAS:排序错误(按变量排序不正确) [英] SAS: sort error (by variable not sorted properly)

查看:1079
本文介绍了SAS:排序错误(按变量排序不正确)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是我在这里提出的另一个问题的后续行动 SAS:数据步骤视图->错误:按变量排序不正确;我要提出一个新问题,因为所需的解决方案略有不同:当我循环浏览多个输入文件时,其中一个原始文件未正确排序,我想知道如何使我的程序跳过该特定输入文件并继续吗?

This question is a follow up from another I had here SAS: Data step view -> error: by variable not sorted properly; I am opening a new question as the desired solution is slightly different: As I am looping through several input files, one of the raw-files is not properly sorted, I wonder what I could do to make my program to skip that particular input file and just continue?

语录:

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

I am using a macro to loop through files based on names and extract data which works fine for the majority of the cases, however from time to time I experience

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

其中CQM_20141113是我从中提取数据的文件。实际上,我的宏在 CQ.CQM_2014:中循环,直到20141113才起作用。由于这一次失败,因此无法创建文件。

where CQM_20141113 is the file I am extracting data from. In fact my macro loops through CQ.CQM_2014: and it works up until 20141113. Because of this single failure the file is then not created.

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

I am using a data step view to "initialize" the data and then in a further step to call data step view (code sample with shortened where conditions):

%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;

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

When I see the error via the log file and I run the file again, then it works (sometimes I need a few trials).

我在考虑proc排序,但是在使用数据步进视图时该怎么做?
请注意,cqm文件很大(这也可能是问题的根源)。
结束报价:

I was thinking of a proc sort, but how to do that when using data step view? Please note the cqm-files are very large (which could also be the root of the problem). End Quote:

编辑:我尝试了您的代码(并在数据步骤视图中删除了by语句),但是出现此错误:

edit: I tried your code (and deleted the by statement in the data step view), however I am getting this error:

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 语句?

Do you need the by statement in the view creation?

如果没有,则从视图中排序为临时数据集:

If not, then sort from the view into a temporary data set:

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 添加排序顺序:

Another option would be to create the view in PROC SQL adding the sort order:

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

这篇关于SAS:排序错误(按变量排序不正确)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆