问题
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