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.
Something like
if missing(v1) then do;
v1 = mean(v2, v3, v4, v5);
end;
You can also use the COALESCE function, which makes for simpler code:
V1=coalesce(V1,mean(of v2-v5));
How to find missing value with the mean of V1 if V1 is numerical variable and V2,V3 & V4 are categorical variables ?
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?
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:
| date | sched_dep_time | dep_time | sched_arr_time | arr_time | carrier | flight | tailnum | origin | dest | distance |
| 1/1/2013 | 515 | 517 | 819 | 830 | UA | 1545 | N14228 | EWR | IAH | 1400 |
| 1/1/2013 | 529 | 533 | 830 | 850 | UA | 1714 | N24211 | LGA | IAH | 1416 |
| 1/1/2013 | 540 | 542 | 850 | 923 | AA | 1141 | N619AA | JFK | MIA | . |
| 1/1/2013 | 545 | 544 | 1022 | 1004 | B6 | 725 | N804JB | JFK | BQN | 1576 |
| 1/1/2013 | 600 | 554 | 837 | 812 | DL | 461 | N668DN | LGA | ATL | 762 |
| 1/1/2013 | 558 | 554 | 728 | 740 | UA | 1696 | N39463 | EWR | ORD | 719 |
| 1/1/2013 | 600 | 555 | 854 | 913 | B6 | 507 | N516JB | EWR | FLL | 1065 |
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.
Ready to level-up your skills? Choose your own adventure.