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. 

sas-innovate-2024.png

Today is the last day to save with the early bird rate! Register today for just $695 - $100 off the standard rate.

 

Plus, pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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