Import 如何在Sas中导入带有字符和数字的.txt
我想在SAS中导入一个.txt文件 下面是我的数据:Import 如何在Sas中导入带有字符和数字的.txt,import,sas,Import,Sas,我想在SAS中导入一个.txt文件 下面是我的数据: annee manufacturier modele categorie cylindree cylindres transmission ville ... 2016 Ford Focus 1 1.8 5 Manual 10.1 2016 Toyota Tercel 3 1.4 3 Auto
annee manufacturier modele categorie cylindree cylindres transmission ville ...
2016 Ford Focus 1 1.8 5 Manual 10.1
2016 Toyota Tercel 3 1.4 3 Auto 7.1
这是我的密码
data car;
infile "C:\Users\Mark\Desktop\sas\car.txt"
LRECL=10000000 DLM=" " firstobs=2 ;
input
annee manufacturier modele categorie cylindree cylindres transmission type ville route combine emissiond indice
;
run;
但是,当我运行它时,我有很多“无效数据…”,然后我在SAS中的表中只有很少的数据,还有很多缺失的数据
有些变量是数字,有些是字符。我觉得问题就在那里
我怎样才能导入那种类型的文件?
谢谢文本文件没有任何内在数据类型。所有内容都是字符,直到您显式地告诉SAS列的数据类型。此外,有时您需要告诉SAS数据的输入格式或信息 有时SAS足够聪明,能够正确猜测您的数据信息。例如,如果删除informat语句,下面的代码将生成相同的结果。但是,这不是说日期的情况。通常,明确指定信息是最佳实践 如果数据是分隔的,例如CSV,则可以使用PROC IMPORT导入数据。使用PROC导入,SAS将根据列的内容对数据类型进行最佳猜测(就像Excel导入文本数据时所做的那样) 以下代码将导入您指定的数据:
filename temp temp;
data _null_;
infile datalines;
file temp;
input;
put _infile_;
datalines;
annee manufacturier modele categorie cylindree cylindres transmission ville
2016 Ford Focus 1 1.8 5 Manual 10.1
2016 Toyota Tercel 3 1.4 3 Auto 7.1
run;
data want;
infile temp firstobs=2;
length
annee 8
manufacturier $20
modele $20
categorie 8
cylindree 8
cylindres 8
transmission $20
ville 8
;
informat
cylindree 8.1
ville 8.1
;
input
annee
manufacturier
modele
categorie
cylindree
cylindres
transmission
ville
;
run;
如果您的数据包含空格,例如manufacturier=Mercedes-Benz,那么您也需要为该列使用informat(例如$char20)