BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
murad130
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
stat_sas
Ammonite | Level 13

Hi,

 

Try this.

 

proc stdize data=mydata.original_data reponly method=mean out=Complete_data;

var X1 X2 X3;
run;

View solution in original post

4 REPLIES 4
stat_sas
Ammonite | Level 13

Hi,

 

Try this.

 

proc stdize data=mydata.original_data reponly method=mean out=Complete_data;

var X1 X2 X3;
run;

murad130
Calcite | Level 5

It worked!

Thank you so much for your help.

Reeza
Super User

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.

 

murad130
Calcite | Level 5

Thank you very much for your help.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

SAS Enterprise Guide vs. SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 17233 views
  • 2 likes
  • 3 in conversation