LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (July 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 5 Jul 2007 21:54:41 -0300
Reply-To:     Adriano Rodrigues - Instituto GPP <adriano@GPP.COM.BR>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Adriano Rodrigues - Instituto GPP <adriano@GPP.COM.BR>
Subject:      Re: Count numbers under hierarchical structure
Comments: To: Suhong Tong <sophidt@HOTMAIL.COM>
In-Reply-To:  <BAY109-F35B8BEAF83F33320C987DDB2020@phx.gbl>
Content-Type: text/plain; charset="windows-1250"

data have; input PR PP PE PA; cards; 123 986 302 32 123 986 302 35 123 986 303 36 123 986 303 38 123 986 303 39

; proc sort; by pr pp pe; proc print; run;

data want; set have; by pe pp pr; if first.pe and first.pp and first.pr then call=0;call+1; proc print; run;

Output: Obs PR PP PE PA call

1 123 986 302 32 1 2 123 986 302 35 2 3 123 986 303 36 1 4 123 986 303 38 2 5 123 986 303 39 3

Works for your data, but if you add this line: 124 986 303 42

This dont work... We get: Obs PR PP PE PA call

1 123 986 302 32 1 2 123 986 302 35 2 3 123 986 303 36 1 4 123 986 303 38 2 5 123 986 303 39 3 6 124 986 303 42 4 <<<----- should be 1 no?

Whats wrong?

Adriano

-----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Suhong Tong Sent: quinta-feira, 5 de julho de 2007 19:39 To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Count numbers under hierarchical structure

Hi Muthia,

Thanks for your suggestion, I tried your way, somehow, the calls keep accumulate regardless whether if it's first.PR or not.

Sophia

>From: "Muthia Kachirayan" <muthia.kachirayan@gmail.com> >To: "Sophia Tong" <sophiDT@hotmail.com> >CC: SAS-L@listserv.uga.edu >Subject: Re: Count numbers under hierarchical structure >Date: Thu, 5 Jul 2007 17:44:23 -0400 > >Sophia, > >Try > >DATA WANT; >SET HAVE; >BY PR PP PE; >IF FIRST.Pe THEN calls + 1; >RUN; > >Muthia Kachirayan > >On 7/5/07, Sophia Tong <sophiDT@hotmail.com> wrote: >> >>Dear list, >> >>I have data under a hierarchical structure: >>PR PP PE PA >>123 986 302 32 >>123 986 302 35 >>123 986 303 36 >>123 986 303 38 >>123 986 303 39 >> >>Here PR can have multiple PPs and PP can have multiple PEs, and PA are >>the unique answers. I want count how many different PEs under the >>same >>PR->PP, >>so I know how many calls have made. >> >>Data I want: >>PR PP PE calls PA >>123 986 302 1 32 >>123 986 302 1 35 >>123 986 303 2 36 >>123 986 303 2 38 >>123 986 303 2 39 >> >> >>What I have tried: >>PROC SORT DATA=HAVE; >>BY PR PP PE; >>RUN; >> >>DATA WANT; >>SET HAVE; >>BY PR PP PE; >>IF FIRST.PR AND FIRST.PP AND FIRST.PR THEN PE_CNT=0; PE_CNT + 1; RUN; >> >>What I got: >>PR PP PE calls PA >>123 986 302 1 32 >>123 986 302 2 35 >>123 986 303 3 36 >>123 986 303 4 38 >>123 986 303 5 39 >> >>Please help. >>Thanks in advance. >> >>Sophia >>

_________________________________________________________________ http://newlivehotmail.com

No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.0/886 - Release Date: 4/7/2007 13:40

No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.476 / Virus Database: 269.10.0/886 - Release Date: 4/7/2007 13:40


Back to: Top of message | Previous page | Main SAS-L page