Import SAS proc导入猜测行问题

Import SAS proc导入猜测行问题,import,sas,dataset,proc,Import,Sas,Dataset,Proc,我正在尝试使用proc导入将csv文件导入SAS;我知道guessingrows参数将自动确定csv文件中每列的变量类型。但是我的一个CSV文件有一个问题,它有两个整列的空白值;我的csv文件中的这些列应该是数字的,但是在运行下面的代码后,这两列将变成字符类型,在将其导入SAS期间或之后,有没有解决方案可以将这两列的类型更改为数字 下面是我运行的代码: proc import datafile="filepath\datasetA.csv" out=dataA dbms=cs

我正在尝试使用proc导入将csv文件导入SAS;我知道guessingrows参数将自动确定csv文件中每列的变量类型。但是我的一个CSV文件有一个问题,它有两个整列的空白值;我的csv文件中的这些列应该是数字的,但是在运行下面的代码后,这两列将变成字符类型,在将其导入SAS期间或之后,有没有解决方案可以将这两列的类型更改为数字

下面是我运行的代码:

proc import datafile="filepath\datasetA.csv"
out=dataA
dbms=csv
replace;
getnames=yes;
delimiter=",";guessingrows=100;
run;

谢谢大家!

您可以通过删除并将其添加回另一种类型来更改缺少所有值的列的列类型

示例(SQL):


可以通过删除并将其添加回另一种类型来更改缺少所有值的列的列类型

示例(SQL):


修改@Richard的代码我会做:

filename csv 'c:\tmp\abc.csv';

data _null_;
  file csv;
  put 'a,b,c,d';
  put '1,2,,';
  put '2,3,,';
  put '3,4,,';
run;

proc import datafile=csv dbms=csv replace out=have;
  getnames=yes;
run;
转到日志窗口,查看PROC导入生成的SAS代码:

data WORK.HAVE    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
    informat a best32. ;
    informat b best32. ;
    informat c $1. ;
    informat d $1. ;
    format a best12. ;
    format b best12. ;
    format c $1. ;
    format d $1. ;
 input
             a
             b
             c  $
             d  $
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro   variable */
 run;
运行此代码并查看最后两列作为字符导入。 检查它:

ods select  Variables;
proc contents data=have nodetails;run;

可以修改此代码并将所需列作为数字加载。我不会在SQL中删除和添加列,因为这些列可能在某个地方有数据

修改的导入代码:

data WORK.HAVE    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
    informat a best32. ;
    informat b best32. ;
    informat c best32;
    informat d best32;
    format a best12. ;
    format b best12. ;
    format c best12;
    format d best12;
 input
             a
             b
             c
             d
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro   variable */
 run;
检查表说明:

ods select  Variables;
proc contents data=have nodetails;run;

修改@Richard的代码我会做:

filename csv 'c:\tmp\abc.csv';

data _null_;
  file csv;
  put 'a,b,c,d';
  put '1,2,,';
  put '2,3,,';
  put '3,4,,';
run;

proc import datafile=csv dbms=csv replace out=have;
  getnames=yes;
run;
转到日志窗口,查看PROC导入生成的SAS代码:

data WORK.HAVE    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
    informat a best32. ;
    informat b best32. ;
    informat c $1. ;
    informat d $1. ;
    format a best12. ;
    format b best12. ;
    format c $1. ;
    format d $1. ;
 input
             a
             b
             c  $
             d  $
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro   variable */
 run;
运行此代码并查看最后两列作为字符导入。 检查它:

ods select  Variables;
proc contents data=have nodetails;run;

可以修改此代码并将所需列作为数字加载。我不会在SQL中删除和添加列,因为这些列可能在某个地方有数据

修改的导入代码:

data WORK.HAVE    ;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
infile CSV delimiter = ',' MISSOVER DSD lrecl=32767 firstobs=2 ;
    informat a best32. ;
    informat b best32. ;
    informat c best32;
    informat d best32;
    format a best12. ;
    format b best12. ;
    format c best12;
    format d best12;
 input
             a
             b
             c
             d
 ;
 if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro   variable */
 run;
检查表说明:

ods select  Variables;
proc contents data=have nodetails;run;

最快的修复方法是编辑csv文件并将
放在
所在的第一行。将它们更改为
,,,
谢谢Richard,我不允许修改原始文档,还有其他方法吗?您似乎已经知道应该如何定义数据。为什么要使用PROC导入?为什么不运行一个数据步骤来读取文件?最快的修复方法是编辑csv文件并将
放在
所在的第一行。将它们更改为
,,,
谢谢Richard,我不允许修改原始文档,还有其他方法吗?您似乎已经知道应该如何定义数据。为什么要使用PROC导入?为什么不运行一个数据步骤来读取文件?