Replace missing values in SAS

让人想犯罪 __ 提交于 2019-11-30 08:37:39

问题


How do you replace all missing values with zeroes in SAS? I have a text file that I dump into SAS to process some geo data, but whenever it has a missing value it breaks the operations. Is there a way to change this without specifying each field? I have over 200.

The way I do so is:

data geo_cali_north;
set geo_cali_north;
if polar_data eq . then 0;
if lat_xvar eq . then 0;
run;

How can I avoid doing this for every field?


回答1:


You can set all the missing values to 0 with like this:

data myData;
set myData;
array a(*) _numeric_;
do i=1 to dim(a);
if a(i) = . then a(i) = 0;
end;
drop i;

This will convert any numeric "." to a 0




回答2:


Another option:

proc stdize data=mydata reponly missing=0 out=newdata;
var _numeric_;
run;

If you have SAS/STAT, probably faster than the datastep option for large datasets.



来源:https://stackoverflow.com/questions/16877705/replace-missing-values-in-sas

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!