LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2006, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Tue, 5 Dec 2006 10:44:08 -0500
Reply-To:   Hari Nath <hari_s_nath@YAHOO.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Hari Nath <hari_s_nath@YAHOO.COM>
Subject:   Re: first. last. by patient and treatment and finally means
Comments:   To: Jack Clark <JClark@CHPDM.UMBC.EDU>

Thanks Jack Clark. This is what i was looking for.....I was kind of learning things (may be a bit slower), but thanks for being patient with my coding.....

thanks again hari

On Tue, 5 Dec 2006 10:35:13 -0500, Jack Clark <JClark@CHPDM.UMBC.EDU> wrote:

>Hari, > >I think you have too much going on in your DATA step. You want the means >calculated within each PAT-TREAT combination. You were correct to SORT and >SET the data by PAT and TREAT. But I think that your first. and last. logic >should only need to be on the PAT field. > >Each time you encounter the first value of a TREAT within a PAT, initialize >SYS, DIA and COUNTER to 0. On every observation, you will increment the >COUNTER and add the b_sys to SYS and add the b_dia to DIA. When you reach >the last observation within that PAT and TREAT, calculate the means (msys >and mdia) and output. > >Is this what you are looking for? > > >data have ; >input pat treat $ b_sys b_dia ; >cards ; > 1 A 10 20 > 1 A 20 30 > 1 A 10 20 > 2 B 30 20 > 2 B 10 10 > 1 C 10 10 > 1 B 20 20 > 1 B 10 20 > ; >run ; > >proc sort data = have ; > by pat treat ; >run ; > >data need ; >retain sys dia; > set have ; > by pat treat ; >if first.treat then do ; > sys = 0 ; dia = 0; counter=0; >end; >counter+1 ; >sys = sum(sys + b_sys); >dia = sum(dia + b_dia) ; >if last.treat then do; > msys = round(sys / counter,.01) ; > mdia = round(dia / counter,.01) ; > * output ; >end ; >run ; > >proc print data = need; >run; > >Jack Clark >Research Analyst >Center for Health Program Development and Management >University of Maryland, Baltimore County > > > >-----Original Message----- >From: Hari Nath [mailto:hari_s_nath@YAHOO.COM] >Sent: Tuesday, December 05, 2006 10:19 AM >To: SAS-L@LISTSERV.UGA.EDU; Jack Clark >Subject: Re: first. last. by patient and treatment and finally means > >Many thanks Jack Clark for your sql solution. But i also want to try that >in a datastep, but iam lost somewhere. > >Could someone correct my program and point me in right way......without >the else statement i could not get the ouput but atleast closer to the >desired output..... > >Thanks for help..... > >**************************program i have********************** >data have ; > input pat treat $ b_sys b_dia ; > cards ; > 1 A 10 20 > 1 A 20 30 > 1 A 10 20 > 2 B 30 20 > 2 B 10 10 > 1 C 10 10 > 1 B 20 20 > 1 B 10 20 > ; >run ; > >proc sort data = have ; > by pat treat ; >run ; > >data need ; > set have ; > by pat treat ; > retain sys dia counter ; > if first.pat then > do; > if first.treat then > do ; > sys = 0 ; dia = 0 ; counter=1 ; > sys = sys + b_sys ; > dia = dia + b_dia ; > > end ; > > else > do ; > sys = sys + b_sys ; > dia = dia + b_dia ; > counter+1; > end ; > end; > > else > do ; > sys = sys + b_sys ; > dia = dia + b_dia ; > counter+1; > end ; > >/* if last.pat then output ;*/ > >run ; > >**********************current output******************************* > > pat treat b_sys b_dia sys dia counter m_sys m_dia ; > > 1 A 10 20 10 20 1 . . > 1 A 20 30 30 50 2 15 25 > 1 A 10 20 40 70 3 13.33 23.33 > 1 B 20 20 60 90 4 15 22.5 > 1 B 10 20 70 110 5 14 22 > 2 B 30 20 80 120 6 13.33 20 > 2 B 10 10 30 20 1 . . > 1 C 10 10 40 30 2 20 15 > > >**********************Desired output******************************* > > pat treat b_sys b_dia sys dia counter m_sys m_dia ; > > 1 A 10 20 10 20 1 . . > 1 A 20 30 30 50 2 . . > 1 A 10 20 40 70 3 13.33 23.33 > 1 B 20 20 20 20 1 . . > 1 B 10 20 30 40 2 15 20 > 2 B 30 20 30 20 1 . . > 2 B 10 10 40 30 2 20 15 > 1 C 10 10 10 10 1 10 10 > >********************************************************************


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