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;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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
  • 874 views
  • 0 likes
  • 2 in conversation