LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (June 1999, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 30 Jun 1999 15:06:58 -0400
Reply-To:     Tim Vorce <timv@TRILLIUMTEAM.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         timv@TRILLIUMTEAM.COM
Subject:      Keeping last unique values
Content-Type: text/plain; charset="iso-8859-1"

My data is sorta like the example. What I want to do is to keep the last unique values where a and b are the control variables, and c is the data. So I want to keep the last unique pair of a and b. A sort nodupkey would be nice, but I understand that it doesn't always keep the last observation.

My complication is that I have another control variable, and I need to keep more than one variable (c here). So this code is looking ugly. Anybody know of a better way to keep the last unique values?

data one; a=1; b=1; c=1;output; a=1; b=1; c=2;output; a=1; b=1; c=3;output; a=2; b=1; c=4;output; a=3; b=1; c=5;output; a=3; b=1; c=6;output; a=4; b=3; c=7;output; a=4; b=3; c=8;output; run;

data two; set one end=last; la=lag1(a); lb=lag1(b); lc=lag1(c); if _n_ ^=1 then do; if a ^= la or b ^= lb then do; output; end; /* a^=lasta */ else do; put a= b= c= la= lb=; end; end; /* _n_ ^= 1 */ if last then do; la=a; lb=b; lc=c; output; end; run; *proc print data=two;run; data _null_; set two; put la lb lc; run;

Tim Vorce (248) 586-1999 Trillium Teamologies SAS. It's not just an attitude

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