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 (October 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 19 Oct 2007 11:59:20 -0400
Reply-To:     Gina Nicolosi <ginanicolosi@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Gina Nicolosi <ginanicolosi@HOTMAIL.COM>
Subject:      Re: simple count and sum
Comments: To: Greg Curson <gscsrc@HOTMAIL.COM>

On Fri, 19 Oct 2007 08:36:20 -0700, Greg Curson <gscsrc@HOTMAIL.COM> wrote:

>Without using Proc tabulate, how can I sum fields base on >values of VAL1 and VAL2(summing VAL3) then counting >the different values of VAL2 and adding them as new values(new >variables to the dataset) >to the records as VAL 4(being the count) and VAL5(being the sum) > >Sample data > VAL2 VAL1 VAL3 > 0002 0501242 48500.00 > 0002 0501242 >63045.38 > 0003 0501242 100.00 > 0003 0501242 118.40 > 0003 0501242 200.00 > 0003 0501242 392.00 > >Results of new dataset > >VAL2 VAL1 VAL4 VAL5 > 0002 0501242 2 111545.38 > 0003 0501242 2 810.40

Greg, If I'm understanding you correctly (and if the value of the 2nd observation of VAL4 is supposed to be 4 instead of 2), you could do...

data sampledata; input val2 val1 val3; cards; 0002 0501242 48500.00 0002 0501242 63045.38 0003 0501242 100.00 0003 0501242 118.40 0003 0501242 200.00 0003 0501242 392.00 ; proc sort; by val1 val2; proc means; by val1 val2; var val3; output out=results (rename=(_FREQ_=val4) drop=_TYPE_) sum()=val5; run;

This will produce val1 val2 val4 val5 501242 2 2 111545.38 501242 3 4 810.4

-gina


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