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 (March 2009, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 3 Mar 2009 09:37:50 -0500
Reply-To:     Akshaya Nathilvar <akshaya.nathilvar@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Akshaya Nathilvar <akshaya.nathilvar@GMAIL.COM>
Subject:      Re: Trying to compute a variable BETOT that is the summation of
              the variable BET1 that lie in the same year, the same with METOT.
Comments: To: barry.brian.barrios@gmail.com
In-Reply-To:  <29e46875-b34a-4c88-95b7-972253b54581@o11g2000yql.googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

In addition to Karma's DOW solution, you can try with SQL. Data have ; input YEAR BET1 MEDECT1 PORTNAME $ ; cards ; 1998 5 5 SH 1998 6 6 SH 1998 5 3 TWOH 1999 1 4 TWOH 1999 2 4 TWOH 1999 5 10 SH ;

Proc sql feedback; select year,portname,sum(bet1) as be_tot,sum(medect1) as me_tot, (calculated be_tot/calculated me_tot) as beme_tot format=4.2 from have group by 1,2 order by 1,2; Quit;

On Tue, Mar 3, 2009 at 1:47 AM, <barry.brian.barrios@gmail.com> wrote:

> Trying to compute a variable BETOT that is the summation of the > variable BET1 that lie in the same year, the same with METOT. > > For example > INPUT: > YEAR BET1 MEDECT1 PORTNAME > 1998 5 5 > SH > 1998 6 6 > SH > 1998 5 3 > TWOH > 1999 1 > 4 TWOH > 1999 2 > 4 TWOH > 1999 5 > 10 SH > > OUTPUT > DATASET > YEAR BETOT METOT BEME_TOT PORTNAME > 1998 11 11 1 SH > 1999 5 10 0.5 SH > 1998 5 3 5/3 TWOH > 1999 3 8 3/8 TWOH > > where BE_TOT is the sum of all BE in the same portfolio in the same > year > and likewise for ME_TOT > > > > > > > CODE: > %macro inname(portname); > %let num = &begyear; > %do %until(&num>&endyear); > data port; > set port; > betot=0; > metot=0; > where year= &num and portname=&portname; > retain betot metot; > betot= sum(bet1,betot); > metot= sum(medect1,metot); > > %let num = %eval(&num+1); > > output; > %end; > run; > > data port; > set port; > beme_port=betot/metot; > run; > > %mend; > %inname(SL); > %inname(STWO); > %inname(STHREE); > %inname(SFOUR); > %inname(SH); > %inname(TWOL); > %inname(TWOTWO); > %inname(TWOTHREE); > %inname(TWOFOUR); > %inname(TWOH); > %inname(THREEL); > %inname(THREETWO); > %inname(THREETHREE); > %inname(THREEFOUR); > %inname(THREEH); > %inname(FOURL); > %inname(FOURTWO); > %inname(FOURTHREE); > %inname(FOURFOUR); > %inname(FOURH); > %inname(BL); > %inname(BTWO); > %inname(BTHREE); > %inname(BFOUR); > %inname(BH); >

-- AkshayA!


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