From: chowdary on
HI,

I have dataset as follows

data have;
id a
1 1
1 0
1 1
2 0
2 1
3 0
3 0
;
data want;
id a count1 count0;
1 1 2
2 1 1
3 0 2
;
I want number of '0' s in field ' a' as count0 and '1' s as
count1
Plz provide solution?

From: Jim Groeneveld on
Hi chowdary,

You could use PROC FREQ and PROC TRANSPOSE and one or more data steps, but
the following is a rather simple solution:

DATA Want;
SET Have; BY ID; * must already be sorted! ;
IF (FIRST.ID) THEN DO;
Count0 = 0;
Count1 = 0;
END;
IF (A) THEN Count1+1; * A supposed only 1 or 0 ;
ELSE Count0+1;
IF (LAST.ID);
RUN;

PROC PRINT Data=Want; RUN;

As you can see your example data contains an inconsistency in the first record.

Regards - Jim.
--
Jim Groeneveld, Netherlands
Statistician, SAS consultant
http://jim.groeneveld.eu.tf

My computer sorrily regrets to communicate our nogo to SGF-2010.


On Tue, 9 Mar 2010 08:17:20 -0800, chowdary
<aramakrishna.chowdary(a)GMAIL.COM> wrote:

>HI,
>
>I have dataset as follows
>
>data have;
>id a
>1 1
>1 0
>1 1
>2 0
>2 1
>3 0
>3 0
>;
>data want;
>id a count1 count0;
>1 1 2
>2 1 1
>3 0 2
>;
>I want number of '0' s in field ' a' as count0 and '1' s as
>count1
>Plz provide solution?