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.
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.