|
sw75@boxfrog.com (Sheila Whitelaw) writes:
+----------------------------------------------------------------
| I need to assign a variable with the last non-blank value of
| monthly variables.
+----------------------------------------------------------------
Sheila,
There are probably many ways to do this -- and I'm sure that the
efficiency experts on the list will post some great ones -- but
this is an 'old school' approach at doing it. It is probably no
more efficient in terms of run time then your code -- but I
think the approach is easier to maintain over the long term.
/* create some test data */
data iset (drop = _I_ _J_);
array m {12} jan feb mar apr may jun jul aug sep oct nov dec;
do _I_ = 1 to 12;
do _J_ = 1 to _I_;
m{_J_} = _J_;
end;
output;
end;
run;
proc print noobs uniform;
run;
/* get last non missing value */
data oset (keep = prev);
set iset;
array m {12} jan feb mar apr may jun jul aug sep oct nov dec;
do _I_ = 12 to 1 by -1;
if (m{_I_} ne .) then do;
prev = m{_I_};
leave;
end;
end;
run;
proc print noobs uniform;
run;
Cheers,
Bob
--
Bob Burnham
bburnham@dartmouth.edu
http://www.dartmouth.edu/~bburnham
|