Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将文本文件导入SAS:Date,不带前导零_Date_Text_Import_Sas_String Length - Fatal编程技术网

将文本文件导入SAS:Date,不带前导零

将文本文件导入SAS:Date,不带前导零,date,text,import,sas,string-length,Date,Text,Import,Sas,String Length,我正在尝试将文本数据文件导入SAS。就是这样, EmployeeID Birthday Gender 10001 5/1/1978 Female 10005 9/16/1982 Male ... 这是我的密码 data employee; infile "employee2015.txt" delimiter=' ' firstobs=2; input employeeid birthday MMDDYY10. gender $; run; 它

我正在尝试将文本数据文件导入SAS。就是这样,

EmployeeID    Birthday   Gender
10001    5/1/1978   Female
10005    9/16/1982   Male
...
这是我的密码

data employee;
   infile "employee2015.txt" delimiter='    ' firstobs=2;
   input employeeid birthday MMDDYY10. gender $;
run;
它不起作用,因为日期的长度是不固定的,所以下一个变量性别会受到影响(比如“emale”会出现)。如果我把它改成MMDDYY8。性别栏中会出现一些数字

我尝试将生日导入为char,它看起来不错,但当我尝试将其格式化为mmddyy10时。将报告错误。我相信一定有一些直接的方法可以做到这一点,所以我在这里寻求帮助


如果您有任何建议,我们将不胜感激。

请删除您的分隔符规范,并创建informat语句,以正确读取数据。您可能需要自定义informat语句以满足实际数据需求

data want;
informat employeeid $5. birthday mmddyy10. gender $8.;
format birthday date9.;
input EmployeeID $   Birthday   Gender $;
cards;
10001    5/1/1978   Female
10005    9/16/1982   Male
;
run;

proc print;run;

非常感谢你!问题完全解决了。但是,我的数据来自文本文件。如果删除分隔符规范,则导入的数据将全部混乱。我认为是informat语句起了作用。可能,但是SAS使用空格作为默认分隔符。如果是选项卡,则应将其指定为“09”x。请尝试使用
anydte.
informat而不是
mmddyy10.