Hello,
I have a data set with several variables (X1, X2, X3,….) and I am trying to replace the missing values in the data set with the mean of the variable.
Here is my sample code:
DATA Complete_data;
Set mydata.original_data;
If X1= . Then X1 = mean(X1);
run;
Unfortunately, it’s not working. Please advise.
Thanks.
Hi,
Try this.
proc stdize data=mydata.original_data reponly method=mean out=Complete_data;
var X1 X2 X3;
run;
Hi,
Try this.
proc stdize data=mydata.original_data reponly method=mean out=Complete_data;
var X1 X2 X3;
run;
It worked!
Thank you so much for your help.
The MEAN function in SAS works only on a row of data.
So the mean of a single variable is the same value, in this case missing.
If you wanted a data step approach you would need two passes, one to calculate the average and a second to merge it in with the data.
PROC STDIZE is easier to work with IMO.
Thank you very much for your help.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.