From: Joe Matise on
One way to go about it is to use GROUP BY in SQL. It cheats with the
'remerge' trick to get your rows back instead of only returning summary
rows.

data test;
input month cost item;
datalines;
1 51 1
1 35 2
1 21 3
1 16 1
1 48 4
1 35 5
2 76 2
2 37 1
2 46 3
2 24 2
2 28 4
2 67 5
2 49 3
;;;;
run;
proc sql;
create table final as select *, sum(cost) from test group by month, item;
quit;

-Joe

On Thu, Jan 14, 2010 at 4:42 PM, Michael Bryce Herrington <
mherrin(a)g.clemson.edu> wrote:

> Hey,
>
> I would like to sum two select values from one variable. In the following
> example I would like to sum the cost variable when the item number is the
> same by each month creating a variable named totalcost. I do not wish to
> remove the observation when this is done. Below is a sample and then what
> I
> wish the final data set to look like. Thanks for your help.
>
> *
>
> data* sample;
>
> input month cost item;
>
> datalines;
>
> 1 51 1
>
> 1 35 2
>
> 1 21 3
>
> 1 16 1
>
> 1 48 4
>
> 1 35 5
>
> 2 76 2
>
> 2 37 1
>
> 2 46 3
>
> 2 24 2
>
> 2 28 4
>
> 2 67 5
>
> 2 49 3
>
> ;
> *
>
> run*;
>
>
>
>
>
>
> *
>
> data* final;
>
> input month cost item totalcost;
>
> datalines;
>
> 1 51 1 67
>
> 1 35 2
>
> 1 21 3
>
> 1 16 1 67
>
> 1 48 4
>
> 1 35 5
>
> 2 76 2 100
>
> 2 37 1
>
> 2 46 3 95
>
> 2 24 2 100
>
> 2 28 4
>
> 2 67 5
>
> 2 49 3 95
>
> ;
> *
>
> run*;
>
>
>
> --
> Bryce Herrington
> Clemson University
> mherrin(a)g.clemson.edu
> (863) 258-4758
>
From: Michael Bryce Herrington on
Thanks that does it!

On Thu, Jan 14, 2010 at 5:50 PM, Joe Matise <snoopy369(a)gmail.com> wrote:

> One way to go about it is to use GROUP BY in SQL. It cheats with the
> 'remerge' trick to get your rows back instead of only returning summary
> rows.
>
> data test;
>
> input month cost item;
> datalines;
> 1 51 1
> 1 35 2
> 1 21 3
> 1 16 1
> 1 48 4
> 1 35 5
> 2 76 2
> 2 37 1
> 2 46 3
> 2 24 2
> 2 28 4
> 2 67 5
> 2 49 3
> ;;;;
> run;
> proc sql;
> create table final as select *, sum(cost) from test group by month, item;
> quit;
>
> -Joe
>
>
> On Thu, Jan 14, 2010 at 4:42 PM, Michael Bryce Herrington <
> mherrin(a)g.clemson.edu> wrote:
>
>> Hey,
>>
>> I would like to sum two select values from one variable. In the following
>> example I would like to sum the cost variable when the item number is the
>> same by each month creating a variable named totalcost. I do not wish to
>> remove the observation when this is done. Below is a sample and then what
>> I
>> wish the final data set to look like. Thanks for your help.
>>
>> *
>>
>> data* sample;
>>
>> input month cost item;
>>
>> datalines;
>>
>> 1 51 1
>>
>> 1 35 2
>>
>> 1 21 3
>>
>> 1 16 1
>>
>> 1 48 4
>>
>> 1 35 5
>>
>> 2 76 2
>>
>> 2 37 1
>>
>> 2 46 3
>>
>> 2 24 2
>>
>> 2 28 4
>>
>> 2 67 5
>>
>> 2 49 3
>>
>> ;
>> *
>>
>> run*;
>>
>>
>>
>>
>>
>>
>> *
>>
>> data* final;
>>
>> input month cost item totalcost;
>>
>> datalines;
>>
>> 1 51 1 67
>>
>> 1 35 2
>>
>> 1 21 3
>>
>> 1 16 1 67
>>
>> 1 48 4
>>
>> 1 35 5
>>
>> 2 76 2 100
>>
>> 2 37 1
>>
>> 2 46 3 95
>>
>> 2 24 2 100
>>
>> 2 28 4
>>
>> 2 67 5
>>
>> 2 49 3 95
>>
>> ;
>> *
>>
>> run*;
>>
>>
>>
>> --
>> Bryce Herrington
>> Clemson University
>> mherrin(a)g.clemson.edu
>> (863) 258-4758
>>
>
>


--
Bryce Herrington
Clemson University
mherrin(a)g.clemson.edu
(863) 258-4758