Desktop productivity for business analysts and programmers

ARRAY referring to current row in do loop

Reply
Occasional Contributor
Posts: 5

ARRAY referring to current row in do loop

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;

Esteemed Advisor
Posts: 7,284

Re: ARRAY referring to current row in do loop

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

 

Occasional Contributor
Posts: 5

Re: ARRAY referring to current row in do loop

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

I really appreciate your help. 

Ask a Question
Discussion stats
  • 2 replies
  • 128 views
  • 0 likes
  • 2 in conversation