我有以下格式的文件:
Name Salary Age
bob 10000 18
sally 5555 20
@not found 4fjfjhdfjfnvndf
@not found 4fjfjhdfjfnvndf
9/2-10/2
但我在文件中有随机点,其中有4-6行随机字符。这些文件有200万行。我想知道infile语句是自动跳过这些随机的行,还是必须进入文件并自动删除这些行。
发布于 2014-02-21 18:42:03
你可能得用某种方式来对付他们。如果truncover
或missover
在infile
语句上,它不会造成任何损害(但是,您必须有一个,否则可能会导致您的下一行被移开)。但是,您需要处理的程序中有一个垃圾行。
快速而肮脏的方法如下所示:
data have;
infile "blah.txt" dlm=' ' dsd lrecl=32767 truncover;
input name $ salary age;
if missing(salary) and missing(age) then delete;
run;
如果垃圾很可能为数字生成缺失的值,那就可以了。但是,您的日志中可能有一些不太好的警告,如果垃圾可能是数字值,这在它发现的内容上也不完美。(如果它完全是数值,则可以测试name
是否是一个数字。)
更好的方法是对_infile_
进行预处理--这有点“高级”,但肯定是一种很好的方法。
data have;
infile "blah.txt" dlm=' ' dsd lrecl=32767 truncover;
input @;
if countw(_infile_) ne 3 then delete; *if there are not exactly 3 "words" then delete it;
if notdigit(scan(_infile_,2)) or notdigit(scan(_infile_,3)) then delete; *if the 2nd or 3rd word contain non-digit values then delete;
input name $ salary age;
run;
这两种方法都需要与数据保持一致才能工作,而且可能需要进行一些调整--例如,如果薪资和年龄可以接受丢失,这两种方法都会删除不想删除的行。
https://stackoverflow.com/questions/21942506
复制相似问题