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 (March 2002, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 13 Mar 2002 14:52:45 -0800
Reply-To:   Jack Shoemaker <shoe@STD.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Jack Shoemaker <shoe@STD.COM>
Organization:   http://groups.google.com/
Subject:   Re: do until loop
Content-Type:   text/plain; charset=ISO-8859-1

Frank,

The data step provides an explicit do-while-not-EOF loop. So, the following would do the trick for you:

data method1( drop = discharges ); set hosp( keep = discharges ) end = lastrec; discharges_sum + discharges; if lastrec then output; run;

HTH - Jack

FIvis@CIHI.CA (Frank Ivis) wrote in message news:<58B9034E84EBD511827D0000D1EE8D902B27EC@MAILTOR>... > I have a question about the code at the bottom. It works properly, > calculating the percentage of discharges for each row. However, in playing > with the code, I noticed something unsual if I run only the first part > before the second set statement: > > data work.method1; > > if _n_=1 then > > do until (last); > > set work.hosp (keep=discharges) end=last; > > discharges_sum+discharges; > > end; > run; > > I expected to get only one record that would contain the sum of the > discharges and the last discharge. Instead, there are TWO identical records. > Why? I thought that once the loop reaches the last record, the data step > ends, since the loop is evaluted at the bottom. > > Thanks in advance, > > Frank > > > /******* Original Code ******/ > data work.hosp; > > input inst_id $ discharges; > > cards; > > 1001 340 > > 1002 2670 > > 1003 990 > > 1004 1050 > > 1005 . > > 1006 887 > > 1007 5896 > > 1008 221 > > ; > > run; > > > > data work.method1; > > if _n_=1 then > > do until (last); > > set work.hosp (keep=discharges) end=last; > > discharges_sum+discharges; > > end; > > set hosp; > > percent_discharges=(discharges/discharges_sum)*100; > > run;


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