【发布时间】:2017-11-29 17:11:10
【问题描述】:
我使用以下代码将数据从 csv 格式导入 SAS。但是,创建的数据集中的数据在错误的行中,如图所示。投标尺寸中的实际数据位于bid_price 中,而bid_size 中的数据缺失。由于某种原因,我无法使用文件>导入数据或proc import。因此,任何人都可以帮我检查我使用的代码吗?
data WORK.want ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile "E:\N69853943.csv" /*obs = 10*/
delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
informat _RIC $25. ;
informat Date_L_ best32. ;
informat Time_L_ time20.3 ;
informat Type $13. ;
informat Ex_Cntrb_ID $1. ;
informat LOC $1. ;
informat Price best32. ;
informat Volume best32. ;
informat Market_VWAP $1. ;
informat Buyer_ID $3. ;
informat Bid_Price best32. ;
informat Bid_Size best32. ;
informat No__Buyers $1. ;
informat Seller_ID $3. ;
informat Ask_Price best32. ;
informat Ask_Size best32. ;
format _RIC $25. ;
format Date_L_ best32. ;
format Time_L_ time20.3 ;
format Type $13. ;
format Ex_Cntrb_ID $1. ;
format LOC $1. ;
format Price best32. ;
format Volume best32. ;
format Market_VWAP $1. ;
format Buyer_ID $3. ;
format Bid_Price best32. ;
format Bid_Size best32. ;
format No__Buyers $1. ;
format Seller_ID $3. ;
format Ask_Price best32. ;
format Ask_Size best32. ;
input
_RIC $
Date_L_
Time_L_
Type $
Ex_Cntrb_ID $
LOC $
Price
Volume
Market_VWAP $
Buyer_ID $
Bid_Price
Bid_Size
No__Buyers $
Seller_ID $
Ask_Price
Ask_Size
;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
run;
【问题讨论】:
-
将 MISSOVER 更改为 TRUNCOVER 并验证您的文件布局结构?是 SAS 认为的变量吗?请注意,上面的代码看起来像是从 PROC IMPORT 步骤自动生成的代码。如果是这样,请在 CSV 上重新运行 PROC IMPORT 并将 GUESSINGROWS 设置得非常高,以便稍后设置长度和类型。
-
请注意,您的 INPUT 在 E/F 列之间显示了一个 LOC 变量。该变量的名称中是否有逗号?还是 / 导致问题?我们看不到全名,所以我无法对此发表评论。
-
这显然是问题所在(LOC),我建议将其发布为@Reeza 的答案。