DATA Step, Macro, Functions and more

How do I group across observations

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

How do I group across observations

Hi,

 

Might be an easy question for a lot of your here. My data is in the following setup:

 

Id Group Sales

1   A  200

1 B 300

2 C 400

 

I want to sum the sales across ids and groups so that there would be only one line item for each id-group combination.

 

Can you please suggest the programming for it?

 

Thanks,

 


Accepted Solutions
Solution
‎06-14-2016 09:51 AM
Super User
Super User
Posts: 7,942

Re: How do I group across observations

There are several methods for this - proc means/summary, proc sql, datastep:

proc means data=have;

  by id;

  var sales;

  output out=want sum=;

run;

 

proc sql;

  create table WANT as

  select ID,

            sum(SALES)

  from   HAVE

  group by ID;

quit;

 

Etc.  

View solution in original post


All Replies
Solution
‎06-14-2016 09:51 AM
Super User
Super User
Posts: 7,942

Re: How do I group across observations

There are several methods for this - proc means/summary, proc sql, datastep:

proc means data=have;

  by id;

  var sales;

  output out=want sum=;

run;

 

proc sql;

  create table WANT as

  select ID,

            sum(SALES)

  from   HAVE

  group by ID;

quit;

 

Etc.  

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 169 views
  • 2 likes
  • 2 in conversation