问题描述
我正在执行 SAS data step with by variable。当数据按键排序(在我的例子中为X
)时,我理解输出。但是,当数据未排序时,我得到以下输出:
我正在使用来自 AFRICA
库的 SAS ODA 的 MAPS
数据集,它有 52824 行。 Here 是 CSV 文件的链接。
data AFRICA_NEW12;
set Maps.AFRICA;
by X;
firstX = FirsT.X;
lastX = LAST.X;
run;
我不明白数据未排序时如何选择行。为什么输出有 14 行?
解决方法
您的日志中有错误,因为您没有对其进行排序。请务必阅读您的日志。
这可能会给您带来同样的问题:
data cars;
set sashelp.cars;
by model;
run;
proc print data=cars;
var make model origin;
run;
输出为:
Obs Make Model Origin
1 Acura MDX Asia
2 Acura RSX Type S 2dr Asia
日志显示:
ERROR: BY variables are not properly sorted on data set SASHELP.CARS.
Make=Acura Model=TSX 4dr Type=Sedan Origin=Asia DriveTrain=Front MSRP=$26,990 Invoice=$24,647 EngineSize=2.4 Cylinders=4
Horsepower=200 MPG_City=22 MPG_Highway=29 Weight=3230 Wheelbase=105 Length=183 FIRST.Model=1 LAST.Model=1 _ERROR_=1 _N_=3
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 4 observations read from the data set SASHELP.CARS.
WARNING: The data set WORK.CARS may be incomplete. When this step was stopped there were 2 observations and 15 variables.
WARNING: Data set WORK.CARS was not replaced because this step was stopped.
特别注意这部分:
警告:数据集 WORK.CARS 可能不完整。当这一步停止时,有 2 个观察值和 15 个变量。
如果您知道数据按您想要的顺序排序,这可能与 SAS 期望的不同,您可以添加 notsorted
option on the BY statement 但这是一种不同类型的功能,因此请检查你的代码彻底。
data cars;
set sashelp.cars;
by model notsorted;
run;