Date: Thu, 29 Jan 2009 03:14:22 -0500
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Can one manipulate the value of first.whatever?
Content-Type: text/plain; charset=ISO-8859-1
The problem you have stems from having an implicit output as the very last
statement in the datastep. That's good enough for most applications,
but in this case tou want to use an explicit output statement, so that
the FIRST_ID variable can be reset after outputting:
data want;
set have;
by id;
if first.id then do;
first_id=1;
if x ne 1 ;
end;
output;
first_id=0;
retain first_id;
run;
Regards,
Søren
On Wed, 28 Jan 2009 19:06:25 -0500, Arthur Tabachneck
<art297@NETSCAPE.NET> wrote:
>Akshaya asked a question earlier today that made me think of a solution
>that required a manipulative first.variable feature. However, I don't
>know how one could accomplish that. For example, given the data file:
>
>data have;
> input id x;
> cards;
>1 1
>1 2
>1 3
>1 4
>2 1
>2 2
>2 3
>3 2
>3 3
>3 4
>;
>
>how can one, or can one, reset first.id if, because of a delete, it isn't
>the first record anymore? For example:
>
>data want;
> set test;
> by id;
> if first.id then do;
> if x eq 1 then do;
> delete;
> /* reset first.id here*/;
> end;
> end;
> first_id=first.id;
>run;
>
>would (if the missing command were added) end up looking like:
>
>data desired_want;
> input id x first_id;
> cards;
>1 2 1
>1 3 0
>1 4 0
>2 2 1
>2 3 0
>3 2 1
>3 3 0
>3 4 0
>;
>
>Just wondering,
>Art
|