Date: Tue, 31 Oct 2006 06:20:16 -0500
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: assign row code
what do you mean with "more elegant"? In deed your method is not really
"elegant", but it leads to unwanted results! Try the following code:
data test;
set sashelp.class;
length code $20;
rowid+1;
code="ab"!!rowid;
run;
proc print;
var rowid code;
run;
that leads results like "ab 1". You should never concatenate chars
with numerics. Better is it, to have it under control:
data test;
set sashelp.class;
length code $20;
rowid+1;
code="ab"!!compress(put(rowid,8.));
run;
proc print;
var rowid code;
run;
Instead of 8. you can use any numeric format, e.g. z4. to get results like
ab0001, ab0002, ...
I don't know a more elegant way...
Regards,
Gerhard
On Tue, 31 Oct 2006 02:49:04 -0800, Arjen <a.benedictus@GMAIL.COM> wrote:
>Hello SAS-L,
>
>I can insert a column ROWID by including this line in datastep:
>
>ROWID+1;
>
>All observations will then be numbered 1 to n(obs).
>
>Now, how can I assign codes to my observations, that have the structure
>ab1, ab2, ab3, .... , ab(n)?
>
>The job could be done by inserting a column CODE="ab" and then
>concatenate CODE and ROWID, but I figure there must be a more elegant
>way to achieve my goal.
>
>Any solutions? Thanks.
>
>Arjen
|