SAS:数据步骤视图->错误:按变量排序不正确 [英] SAS: Data step view -> error: by variable not sorted properly
问题描述
我正在使用宏来循环基于名称的文件并提取数据,这在大多数情况下都可以正常工作,但是我有时会遇到
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.
我正在使用数据步骤视图来初始化"数据,然后在进一步的步骤中调用数据步骤视图(带有缩短 where 条件的代码示例):
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).
taq_ds
不是一个单一的文件,而是贯穿几个以CQM_2014
开头的文件,即CQM_20140101、CQM_20140102等
edit: taq_ds
is not a single file but runs through several files whose name start with CQM_2014
, i.e. CQM_20140101, CQM_20140102, etc.
推荐答案
根据提供的代码,您可以将第一个数据步骤视图替换为 SQL 视图:
Based on the code provided, you could replace your first data step view with a SQL one:
proc sql;
create view _v_&tables as
select * from &taq_ds
where sym_root = &stock
order by sym_root, date, time_m;
或者,您可以为数据步骤视图添加一个类似视图的前缀.这将强制执行后续 by
语句所需的排序.
Alternatively you could prefix your data step view with a similar view. This would enforce the ordering needed for the subsequent by
statement.
这篇关于SAS:数据步骤视图->错误:按变量排序不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!