BookmarkSubscribeRSS Feed
kvera40
Calcite | Level 5

Hello! 

I am setting up an array with a do-loop.. I need to create a do-loop block that will replace a missing value of trip 1 trhough 5 with the mean of the first trips.. I cannot figure out how to set up the do-loop to command it to replace the missing value (.) with the mean of the first 5 trips.. Please help. 

 

 

data tripinfo;
infile datalines truncover;
input custno trip1 trip2 trip3 trip4 trip5 trip6 trip7 trip8 trip9 trip10;

datalines;
123 200 225 432 300 100 550 80 325 600 270
124 2000 3000 2205 1400 1385 1240 1000
125 900 890 1000 1025 1200 1120 1000 800 750 300
126 3000 3000 3000 3000 3000
127 699 599
;
run;

2 REPLIES 2
art297
Opal | Level 21

Not sure if this is what you want, but . . .

 

data tripinfo (drop=mean);
  infile datalines truncover;
  input custno trip1 trip2 trip3 trip4 trip5 trip6 trip7 trip8 trip9 trip10;
  array means trip1-trip10;
  mean=mean(of trip1-trip5);
  do over means;
    if missing(means) then means=mean;
  end;
  datalines;
123 200 225 432 300 100 550 80 325 600 270
124 2000 3000 2205 1400 1385 1240 1000 . . .
125 900 890 1000 1025 1200 1120 1000 800 750 300
126 3000 3000 3000 3000 3000 . . . . .
127 699 599 . . . . . . . .
;
run;

Art, CEO, AnalystFinder.com

 

kvera40
Calcite | Level 5

Thank you !! I could not figure out how to set it to generate the mean in the missing fields. 

I really appreciate 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

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 2 replies
  • 1076 views
  • 0 likes
  • 2 in conversation