Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sum of rows

Status
Not open for further replies.

proximo20

Technical User
Sep 29, 2009
22
US
My dataset looks like this

ID X

1001 5
1002 3
. .
. .
1002 4
1003 3
1003 6
1003 4
. .
. .
1003 3
1004 2
. .
. .
. .

Now I need only one ID and X value in each row. For example I need the sum of X values for the ID number 1002.

The problem is that the sequence always change. Sometimes I see the same Id number in the next three lines sometimes in the next 8 lines.
 
I'd use proc sql for this and sum X.

Code:
proc sql;
create table newtable as
select ID, sum(X) as SumofX
from yourtable
group by ID;
quit;

Dave
 
Alternatively to keep this in native SAS:-
Code:
proc summary data=dset nway;
  class ID;
  var x;
  output out=new_dset(drop=_type_) sum=;
run;

Chris
Business Analyst, Code Monkey, Data Wrangler.
SAS Guru.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top