DATA Step, Macro, Functions and more

Somme Sql

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Somme Sql

 

Hello,

I have a table, I would like in SQL the sum of prices per ID.

 

Thanks for your help

 

 Table:                                                                                              what I want:

IDPrice   IDSomme Price
14714   14714
14545   14563
17417   17417
14518   17883
17818   179868
179845   1456767
1456767   164634
164634     
179823     
17865     
       

Accepted Solutions
Solution
3 weeks ago
Super User
Super User
Posts: 9,193

Re: Somme Sql

Something like:

proc sql;
create table want as
select id,sum(price) as some_price from have group by id;
quit;

View solution in original post


All Replies
PROC Star
Posts: 1,190

Re: Somme Sql

Do like this

 

data have;
input ID$ Price;
datalines;
147 14 
145 45 
174 17 
145 18 
178 18 
1798 45 
14567 67 
1646 34 
1798 23 
178 65 
;

proc sql;
   create table want as
   select ID, sum(Price) as SumPrice
   from have
   group by ID;
quit;
Contributor
Posts: 32

Re: Somme Sql

proc tabulate data=HAVE out=want (drop =_type_ _page_ _table_ Price_N);
  class ID;
  var Price;
  tables ID, Price*(sum);
   ;
run;
Solution
3 weeks ago
Super User
Super User
Posts: 9,193

Re: Somme Sql

Something like:

proc sql;
create table want as
select id,sum(price) as some_price from have group by id;
quit;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 102 views
  • 0 likes
  • 4 in conversation