Date: Mon, 25 Sep 2006 13:02:48 -0400
Reply-To: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Muthia Kachirayan <muthia.kachirayan@GMAIL.COM>
Subject: Re: numbering observations
In-Reply-To: <4FB5A1689D998C40B6BE0E8A7D1C8AB2266C1E@usctmx1124.merck.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Paul M.
Can I do this way?
data a_need ;
do until (a ne .) ;
set a;
if not missing(a) then b = 0;
b + 1;
output ;
end ;
run ;
Regards,
Muthia Kachirayan
On 9/25/06, Dorfman, Paul <paul_dorfman@merck.com> wrote:
>
> Arjen,
>
> A simple way is, as already indicated,
>
> data a_need ;
> set a ;
> if a ne . then b = 1 ;
> else b ++ 1 ;
> run ;
>
> An alternative way based on the DoW logic (loop until stop-event) could
> be:
>
> data a_need ;
> do b = 1 by 1 until (a ne .) ;
> output ;
> set a ;
> end ;
> run ;
>
> But this produces an extra first observation. Of course, subsequently
>
> set a_need (firstobs=2)
>
> could be used, but it is a classic kludge. Try finding a kludge-free way
> of eliminating the extra observation in the dow-step itself. Then
> reflect on the fact that if SET and OUTPUT followed the "normal" order,
> the extra record would be gone, but then the numbering would be off by
> 1. Think of the most aesthetic way to correct that (within the same
> step, of course). It can be a useful exercise leading to a deeper
> understanding how the DATA step works. Actually, this is the only reason
> I offer this - as a puzzle rather than a solution.
>
> Kind regards
> ------------
> Paul Dorfman
> Jax, FL
> ------------
>
>
> +-----Original Message-----
> +From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
> +Behalf Of Arjen
> +Sent: Monday, September 25, 2006 10:41 AM
> +To: SAS-L@LISTSERV.UGA.EDU
> +Subject: numbering observations
> +
> +
> +Hello all,
> +
> +I have dataset A:
> +
> +data A;
> +input A;
> +cards;
> +1
> +.
> +.
> +2
> +.
> +.
> +1
> +.
> +.
> +.
> +;
> +run;
> +
> +I would like to obtain dataset A_need:
> +
> +data A_need;
> +input A B;
> +cards;
> +1 1
> +. 2
> +. 3
> +2 1
> +. 2
> +. 3
> +1 1
> +. 2
> +. 3
> +. 4
> +;
> +run;
> +
> +As you can see, I want to number the observations "within" a given A.
> +The point is that I cannot sort the table because the data is arranged
> +in a peculiar way. As a result, the following code:
> +data A_need;
> +set A;
> +by A;
> +if first.A then B=1;
> +else B+1;
> +run;
> +
> +does not work as it requires sorting by A. In my dataset are several
> +other variables, all character. I would appreciate your help. Thanks.
> +
> +Arjen
> +
> +
>
>
>
> ------------------------------------------------------------------------------
> Notice: This e-mail message, together with any attachments, contains
> information of Merck & Co., Inc. (One Merck Drive, Whitehouse Station,
> New Jersey, USA 08889), and/or its affiliates (which may be known
> outside the United States as Merck Frosst, Merck Sharp & Dohme or MSD
> and in Japan, as Banyu - direct contact information for affiliates is
> available at http://www.merck.com/contact/contacts.html) that may be
> confidential, proprietary copyrighted and/or legally privileged. It is
> intended solely for the use of the individual or entity named on this
> message. If you are not the intended recipient, and have received this
> message in error, please notify us immediately by reply e-mail and then
> delete it from your system.
>
>
> ------------------------------------------------------------------------------
>
|