Desktop productivity for business analysts and programmers

Conditional SUM for rows

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 111
Accepted Solution

Conditional SUM for rows

Hello,

I have a dataset that looks like this:

 

year orig dest flow
1990 AT BE 456
1990 AT DE 356
1990 AT DE  21
1990 BE DE 235

 

I would like to sum the column "flow" when year, orig and dest have the same value. For instance, in that example, the dataset should become:

 

year orig dest flow
1990 AT BE 456
1990 AT DE 377
1990 BE DE 235

 

Is there a simple way to do this?


Accepted Solutions
Solution
‎04-24-2017 09:56 AM
Super User
Super User
Posts: 7,731

Re: Conditional SUM for rows

Post test data in the form of a datastep!

 

proc sql;
  create table WANT as
  select  YEAR,
          ORIG,
          DEST,
          sum(FLOW) as FLOW
  from    HAVE
  group by YEAR,ORIG,DEST;
quit;

As  a guess. 

View solution in original post


All Replies
Solution
‎04-24-2017 09:56 AM
Super User
Super User
Posts: 7,731

Re: Conditional SUM for rows

Post test data in the form of a datastep!

 

proc sql;
  create table WANT as
  select  YEAR,
          ORIG,
          DEST,
          sum(FLOW) as FLOW
  from    HAVE
  group by YEAR,ORIG,DEST;
quit;

As  a guess. 

☑ This topic is solved.

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

Discussion stats
  • 1 reply
  • 256 views
  • 1 like
  • 2 in conversation