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.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 18362 views
  • 2 likes
  • 3 in conversation