Hi I need to replace all missing values in a dataset with respective mean.
Find the sample i wrote.
%macro replace_missing(dataset);
proc means data=&dataset mean ; ;
output out=t (drop=_type_ _freq_) mean=/autoname;
run;
proc transpose data=t out=tr;
run;
data _null_;
set Tr end=last ;
call symput('mean'||left(_n_),col1);
if last then call symput('maxi', _n_);
/* x=left(_N_) */;
/* put _N_ maxi last x ; */;
run;
data &dataset;
set &dataset;
array num(*) _numeric_;
%do n=1 %to &maxi;
if num(&n)=. then num(&n)= &&mean&n;
%end;
run;
%mend;
%replace_missing(drop_missing);
run;
But this is not working..
Please help
supersonic
Proc STANDARD will do this for you, see code sample below.
Works well with this dataset:
data one;
input thing;
datalines;
100
101
.
103
104
105
;
Can you give the log or the dataset you tried to use it with?
Hi Murray
Its a very huge dataset.
My aim is to replace all the missing values with the corresponding mean value
As stated by https://communities.sas.com/people/Murray_Court, attach a log or describe in more detail what it is that does not work...
Base SAS(R) 9.4 Procedures Guide (PROC standard replacing missing by mean) == Bruno-s ==
The advantage of this procedure is it is part of SAS/Base Procs
If it should be more advanced like being in the Eminer processing, That one is using
SAS/STAT(R) 12.3 User's Guide (Proc MI) .
You nee to be licnesed for that.
proc stdize data=old out=new missing=mean reponly;
var _numeric_;
run;
You can also calculate the median first, then read values from a second data set
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.