BookmarkSubscribeRSS Feed
Sudheer1
Calcite | Level 5

How to replace missing values of a variable with the mean of another variable.

For example:

Replace the missing values for V1 with the average V2 on V3,V4 and V5.

7 REPLIES 7
andreas_lds
Jade | Level 19

Something like

if missing(v1) then do;
    v1 = mean(v2, v3, v4, v5);
end;
s_lassen
Meteorite | Level 14

You can also use the COALESCE function, which makes for simpler code:

V1=coalesce(V1,mean(of v2-v5));
Sudheer1
Calcite | Level 5

How to find missing value with the mean of V1 if V1 is numerical variable and V2,V3 & V4 are categorical variables ?

ChrisNZ
Tourmaline | Level 20

1. Have you tried the suggestions given?

If not, please do it and report.

 

2. So you want to calculate the average for numbers contained in character variables?

Sudheer1
Calcite | Level 5
I need to find missing value for by using mean of V1 and group by V2, V3 &
V4.
Jagadishkatam
Amethyst | Level 16
Hi Sudheer

please provide the data structure or an example dataset you have and expected output to get better response and solution.

Depending on the structure of the data the code will change.
Thanks,
Jag
Sudheer1
Calcite | Level 5

Hi Jagadish,

 

I need to replace the missing values for distance with mean of distance and group by carrier, origin and dest.

Please find the sample data below:

datesched_dep_timedep_timesched_arr_timearr_timecarrierflighttailnumorigindestdistance
1/1/2013515517819830UA1545N14228EWRIAH1400
1/1/2013529533830850UA1714N24211LGAIAH1416
1/1/2013540542850923AA1141N619AAJFKMIA.
1/1/201354554410221004B6725N804JBJFKBQN1576
1/1/2013600554837812DL461N668DNLGAATL762
1/1/2013558554728740UA1696N39463EWRORD719
1/1/2013600555854913B6507N516JBEWRFLL1065

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 1941 views
  • 3 likes
  • 5 in conversation