使用 INFILE 的 SAS PROC 导入与数据步骤

SAS PROC Import vs DATA step with INFILE

当我尝试读取包含地址字段的“~”分隔文件时,我的 PROC IMPORT 步骤出错了 "import unsuccessful"。在 CSV 文件中,5 字节的邮政编码被自动视为数字字段,有时我会收到带有无效邮政编码的错误数据记录,如 VXR1@。遇到这种情况时,我收到 "import unsuccessful" 错误并且 SAS 作业失败。 PROC IMPORT 会自动转换为带有 infile 的 DATA 步骤。因此,我尝试使用 INFILE 选项以及 INFORMATS 和 FORMATS 执行 DATA 步骤,并将 ZIP 的 FORMAT 更改为字母数字。但我现在面临不同的问题。使用 DATA、INFORMAT 和 FORMAT 关键字时,会发生长度不匹配,数据会自动移动到不同的位置。有人可以帮我找出解决这个问题的方法吗?

包括我使用的PROC IMPORT和我在下面使用的DATA文件步骤供参考:

data WORK.TRADER_STATS                               ;
            %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
            infile '/sascode/test/TRADER_STATS.csv' delimiter = '~' MISSOVER DSD lrecl=32767 firstobs=2 ;
               informat TRADER_id best32. ;
               informat dealer_ids . ;
               informat dealer_name . ;
               informat dealer_city . ;
               informat dealer_st . ;
               informat dealer_zip . ;
               informat SNO best32. ;
               informat start_dt yymmdd10. ;
               informat end_dt yymmdd10. ;
            input
                        TRADER_id
                        dealer_ids $
                        dealer_name $
                        dealer_city $
                        dealer_st $
                        dealer_zip
                        sno
                        start_dt
                        end_dt
           ;
            if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
            run;


proc import file="/sascode/test/TRADER_STATS_BY_DAY.csv" out=WORK.TRADER_STATS_BY_DAY
dbms=dlm replace;
delimiter='~';
;run;

尝试使用 这将告诉 SAS 使用提供的信息但在遇到分隔符时停止读取此变量的值,这将解决您的问题 - 数据移动到不同的自动定位

data WORK.TRADER_STATS                               ;
            %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
            infile '/sascode/test/TRADER_STATS.csv' delimiter = '~' MISSOVER DSD lrecl=32767 firstobs=2 ;
            input       TRADER_id : best32.
                        dealer_ids : .
                        dealer_name : .
                        dealer_city : . 
                        dealer_st $ : . 
                        dealer_zip : . 
                        sno : best32. 
                        start_dt : yymmdd10. 
                        end_dt : yymmdd10.;
            if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
            run;