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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of 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
  • 650 views
  • 0 likes
  • 2 in conversation