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;
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
Thank you !! I could not figure out how to set it to generate the mean in the missing fields.
I really appreciate your help.
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!
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.