Date: Mon, 15 Apr 1996 20:20:24 GMT
Reply-To: dstanle@ibm.net
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Don Stanley <dstanle@IBM.NET>
Organization: Information Power
Subject: Re: need help on this program
and an sql alternative
proc sql ;
create table count as
select *,count(id) from test
group by id ;
quit ;
don
In <199604151732.KAA21214@dfw-ix4.ix.netcom.com>, "ADITYA K. JHA"
<jhadas@IX.NETCOM.COM> writes:
>The easiest way to set up a counter for observations (I am assuming you
>wish to sequentially count each observation within ID) is to use a BY
>statement in conjunction with a SET statement and a FIRST.variable
>statement.
>
>Like this:
>
>data test;
> infile datalines;
> input @1 id;
>datalines;
>AA
>AA
>BB
>BB
>BB
>CC
>DD
>DD
>DD
>DD
>;
>
>run;
>
>proc sort;
> by id;
>run;
>
>data count;
> set test;
> by id;
>
>if first.id then
> counter=1;
> else
> counter+1;
>run;
>
>Hope this helps.
>
>Frank Basile
> Ragtime Guitarist
> and
>Aspiring Computer Geek
>
>You wrote:
>>
>>I would like to create the counts for each id like this. If any ane
>knows
>>please
>>post the answer or email me.
>>
>>
>>Input:
>>
>>ID
>>----
>>AA
>>AA
>>BB
>>BB
>>BB
>>CC
>>DD
>>DD
>>DD
>>DD
>>
>>
>>OUTPUT:
>>
>>ID CNT
>>---- ---
>>AA 2
>>AA 2
>>BB 1
>>BB 2
>>BB 3
>>CC 1
>>DD 1
>>DD 2
>>DD 3
>>DD 4
>>
==============================================================================
=
Don Stanley DSTANLE@IBM.NET Information Power Limited
SAS Institute Quality Partners
Wellington NEW ZEALAND
Author : Beyond The Obvious With SAS Screen Control Language
Currently Writing : Effective Use Of The Frame Entry In SAS Software
(Working title)
another chapter bites the dust ...