我有以下格式的文件:
Name Salary Age
bob 10000 18
sally 5555 20
@not found 4fjfjhdfjfnvndf
@not found 4fjfjhdfjfnvndf
9/2-10/2
但是然后我在文件中有4-6行随机字符的随机点。这些文件有200万行。我想知道infile语句是否自动跳过这些随机的行,还是我必须进入文件并自动删除这些行。
您可能必须以某种方式处理它们。如果你有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;
两种方法都需要与数据保持一定的一致性才能正常工作,并且可能需要进行一些调整-例如,如果可以接受工资和年龄的缺失,这两种方法都会删除您不希望删除的行。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句