LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (May 2002, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 2 May 2002 15:49:32 -0400
Reply-To:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Organization:   Dartmouth College, Hanover, NH, USA
Subject:   Re: Last non-Blank value
Content-Type:   text/plain; charset=us-ascii

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


Back to: Top of message | Previous page | Main SAS-L page