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 (May 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 26 May 2005 15:47:38 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: problem in taking sum
Comments: To: way2vb@YAHOO.COM
In-Reply-To:  <20050526080304.98231.qmail@web30213.mail.mud.yahoo.com>
Content-Type: text/plain; format=flowed

Vinoth,

data one ; infile cards ; input ID Amount Date ; cards; 1 20 04031996 1 10 04021996 1 30 04011996 2 40 04071996 2 50 04021996 ; run;

/**********************************/ /** SQL Solution **/ /**********************************/

proc sql ; create table Sum1 as select ID , Sum(Amount) as Amount , Max(Date) as Date from one group by ID ; quit ;

/**********************************/ /** Data Step Solution **/ /**********************************/

proc sort data = one ; by ID Date ; run ;

data Sum2 (drop = _Amount) ; set one (rename = (Amount = _Amount)) ; by ID Date ;

Amount + _Amount ;

If last.ID then do ; Output ; Amount = 0 ; end ;

run ;

/***********************************/ /** Proc Means Solution **/ /***********************************/

Proc Means data = one nway noprint ; by ID ; var Amount ; output out = Sum3 (Drop = _type_ _freq_ ) sum = Amount max(Date) = Date; run ;

/***********************************/ /** Proc Summary Solution **/ /***********************************/

Proc Summary data = one nway ; by ID ; Var Amount ; output out = Sum4 (Drop = _type_ _freq_ ) sum = Amount max(Date) = Date ; run ;

/***************************************/ /** DOW Solution **/ /***************************************/

proc sort data = one ; by ID Date ; run ;

data sum5 (drop = _Amount) ; Amount = 0 ;

do until (last.ID) ; set one (rename = (Amount = _Amount)) ; by ID ; Amount + _Amount ; end ;

run ;

Toby Dunn

From: vinoth babu <way2vb@YAHOO.COM> Reply-To: vinoth babu <way2vb@YAHOO.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: problem in taking sum Date: Thu, 26 May 2005 09:03:04 +0100

Hi,

I have dataset having multiple records per repondence. It looks like the below dataset.

ID Amount Date 1 20 04031996 1 10 04021996 1 30 04011996 2 40 04071996 2 50 04021996

I need dataset having unique ID value and sum of the amount and recent date.

Result should be

ID Amount Date 1 60 04031996 2 90 04071996

Any ideas

Thanks

VB

________________________________________________________________________ Yahoo! India Matrimony: Find your life partner online Go to: http://yahoo.shaadi.com/india-matrimony


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