Date: Mon, 6 Mar 2006 22:18:46 -0500
Reply-To: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <rdevenezia@WILDBLUE.NET>
Subject: Re: Summing data on multiple variables???
wardnine@hotmail.com wrote:
> Hello... I have a dataset with a numeric fund, function, object, and
> amount variables. There are thousands of possible fund, function, and
> object combinations and the same fund, function, and object
> combination can appear multiple times. I am looking to create a
> dataset which gives me the sum total of each distinct fund, function,
> and object combination (e.g., I would want to sum the amounts for all
> the observations that have the same fund, function, and object
> numbers). For example, if there is are 4 observations with fund =
> 400, function = 1000, and object = 30, I would want those
> obseravtions summed on the amount variable because they have the same
> fund, function, and object. How would I do this?? I was able to
> isolate the distinct fund, function, object combinations by doing
> proc sort by fund function object with the nodupkey option but the
> amount line only gives you the amount for the first (or last)
> occurance of a particular fund, function, object combination - not
> the sum total. If any one can help here that would be appreciated,
> thanks!!!
One way is to use Proc SUMMARY.
%let seed = 123;
data foo;
do rows = 1 to 5e5;
fund = floor(50 * ranuni(&seed));
function = floor(100 * ranuni(&seed));
object = floor(25 * ranuni(&seed));
amount = floor(100 * ranuni(&seed));
output;
end;
run;
proc summary noprint data=foo ;
class fund function object;
var amount;
output out=sums(drop=_type_) sum=amount_sum;
types fund*function*object;
run;
--
Richard A. DeVenezia
http://www.devenezia.com/
|