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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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