Date: Sun, 20 Nov 2005 15:42:17 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Question about do loop
In-Reply-To: <3ubavoF10n9m6U1@individual.net>
Content-Type: text/plain; format=flowed
Richard,
Very true and you wont hear any argument out of me on this point. I was
running out of time when I wrote that post and i am glad that you brought
the point out for further discussion. I guess I really should have
explained further when I got home. Seems I failed to do that. And just for
those interested in what Richard is saying run the following code and look
at the log:
data one ;
infile cards ;
input id $ ;
cards ;
A
A
A
A
B
B
C
D
D
D
E
E
E
;
run ;
Data _null_ ;
put 'Before Loop' ;
put _all_ ;
Do I= first.id by 1 until (last.id); /**<-- made a correction to the
original code**/
Set one;
By ID;
put 'In Loop' ;
put _all_ ;
End;
put 'After Loop' ;
put _all_ ;
Run;
Toby Dunn
From: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Reply-To: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Question about do loop
Date: Sun, 20 Nov 2005 08:12:30 -0500
"toby dunn" <tobydunn@HOTMAIL.COM> wrote in message
news:BAY101-F399A4DB8650493BDCD397BDE5F0@phx.gbl...
> John,
>
> I will write more later tonight as I am running out the door for my 2.5
hour
> trip home. The Automatic variable first.id will always be equal to one
for
> the observation at the begining of a given group and zero for the rest of
> the observations in that group.
>
> Toby Dunn
>
> From: ma015b8234 <ma015b8234@BLUEYONDER.CO.UK>
> Reply-To: ma015b8234 <ma015b8234@BLUEYONDER.CO.UK>
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Question about do loop
> Date: Thu, 17 Nov 2005 22:31:51 -0000
>
> Dear SAS-L Contributors:
>
> A question about the behavior of the variable which indicates the number
of
> times the loop has been carried out:
>
> Data aa;
> Do I= first.id by 1 until (last.id;
> Set bb;
> By ID;
> End;
> Run;
>
> Why does 'I' start with a value of 1 in the first loop and in the
subsequent
> loops it starts with a value of 0-it is inconsistent.
>
> John
Toby:
One cause of presumed inconsistency is that second (and subsequent) times
when first.id is evaluated for the loop start index, it will be retaining
the first.id value as set at the end of the prior group. If a by group has
one row, you would find I starts at 1 for the next by group;
BlueYonderer:
The likely principal cause of confusion is that in the _N_=1 implicit
iteration, all the first. variables will be set to 1 _prior_ to the SET
statement. This is a similar 'confusion' for other options such as NOBS=,
the 'side-effect' variable related to the statement is automatically
assigned prior to the statement.
--
Richard A. DeVenezia
http://www.devenezia.com/