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 (April 2011, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 7 Apr 2011 14:32:38 -0700
Reply-To:   Daniel Nordlund <djnordlund@FRONTIER.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Daniel Nordlund <djnordlund@FRONTIER.COM>
Subject:   Re: Counter SAS programming
Comments:   To: "Mao, Viola (CONT)" <Viola.Mao@CAPITALONE.COM>
In-Reply-To:   <0A8ACCA61C16B547ADC49EDF83A0D45F4A641BA854@KDCPEXCMB07.cof.ds.capitalone.com>
Content-Type:   text/plain; charset="us-ascii"

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Mao, Viola (CONT) Sent: Thursday, April 07, 2011 1:12 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Counter SAS programming

I understand the codes are correct. But why is there no "retain" for _1_Y and _last_Y

Thanks

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Yu Zhang Sent: Thursday, April 07, 2011 3:48 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Counter SAS programming

data want ; do until (last.id); set alldata; by id; if enroll='Y' and missing(_1_Y) then _1_Y=1; if enroll='N' and _1_Y then _last_Y =1;

if _1_Y and not _last_Y then output; end; run;

Viola,

I like Yu Zhang's response. Often when one needs to do things BY some variable(s) and values need to be reset when done with a group of BY variables, it is often useful to use a DO UNTIL loop. This is the case here.

The reason a retain is not necessary is that the SET statement is inside a DO UNTIL loop, so calculated variables only get reset after leaving the loop and then hitting the end of the datastep and returning to the beginning of the implicit datastep loop. So long as you only need values "retained" within the DO WHILE a retain is not necessary. You also get the bonus that variables will be reset after finishing with a BY GROUP.

Hope this is helpful,

Dan

Daniel Nordlund Bothell, WA USA


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