BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

I have this observations like this:

Testplace Method capacity
Testplace A Normal 1213
Testplace A Normal 1333

 

I need to sum up the capacity for testplace A so it becomes one line

testplace Method capacity
testplace A normal 2546

 

with proc sql?

1 REPLY 1
Shmuel
Garnet | Level 18

You can use any of next methods:

/* 1 */
proc summary data=have nway;
  class name method;
  var capacity;
  output out=want(drop _freq_ _type_) sum=;
run;

/* 2 */
proc sql;
  create table want as
  select testplace, method, sum(capacity) as capacity
 from have
 group by testplace, method;
quit;

/*3 */
proc sort data=have; by testplace method; run;
data want;
 set have;
  by testplace method;
      retain total;
      if first.method then total=0;
      total+capacity;
      if last.method then do;
         capacity=total;
         output;
      end;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 776 views
  • 0 likes
  • 2 in conversation