我有一组数据,我想用SAS操作:这是我的代码,但似乎日期格式有问题:
/*DATA:
3241 F 100287012
13431043321110310022
5673 M 211178124
11031002231134310433
4702 M 170780025
31134310433211103100
2496 F 030979013
22311542102231152111
6543 M 090885124
03100343104332111031 */
/*
1st Row.
Input ID 4. Gender $ Birthdate 6. Race 1. Marital 1. Status_and_Education 1. @@;*/
Data Survey;
Infile "/folders/myfolders/surveydata.txt";
Input ID 4. Gender $ Birthdate 6. Race 1. Marital 1. Status_and_Education 1. @@;
Input / Reponse_1 5. Reponse_2 1. Reponse_3 1. Reponse_4 1. Reponse_5 1.
Reponse_6 1. Reponse_7 1. Reponse_8 1. Reponse_9 1. Reponse_10 1.
Reponse_11 1. Reponse_12 1. Reponse_13 1. Reponse_14 1. Reponse_15 1.
Reponse_16 1. Reponse_17 1. Reponse_18 1. Reponse_19 1. Reponse_20 @;
format Birthdate ddmmyy8.;
run;
proc print data=Survey;
format Birthdate DDMMYY.;
run;
这是输出:
答案 0 :(得分:0)
您没有将变量BIRTHDATE读作日期,而是将其读作常规数字。因此,对于数据的第一行,我看到此字符串100287
,您将其读作数字100,287。由于今天是第21,169天,该值代表一天超过79,000天或超过216年。
尝试这样的代码。注意我喜欢使用YMD订单来代替MDY或DMY订单,以避免在处理来自世界不同地区的人/数据时产生混淆。
data Survey;
infile "/folders/myfolders/surveydata.txt";
input ID 4. +1 Gender $1. +1 Birthdate ddmmyy6. Race 1.
Marital 1. Status_and_Education 1.
/ Response_1 5. (Response_2-Response_20) (1.)
;
format Birthdate yymmdd10.;
run;