BookmarkSubscribeRSS Feed
alsi21ac
Calcite | Level 5

Hi all,

I'm after some assistance.

 

I need to sum the total_casualties if the same type of disaster occurs twice (or more) in the same year. My dataset looks approximately like this one:

   Country  Year Disaster_type  Total_casualties
Afghanistan 1990     Flood           2134
Afghanistan 1990     Flood           3456
Afghanistan 1993    Epidemic         111
...
Afghanistan 2020     Storm           345
Albania     1992    Landslide        222
Albania     1992    Landslide        111
Albania     1994     Storm           555
...
Albania     2014    Epidemic         5675

What I want to obtain is a dataset like this one:

 

   Country  Year Disaster_type  Total_casualties
Afghanistan 1990     Flood           5590
Afghanistan 1993    Epidemic         111
...
Afghanistan 2020     Storm           345
Albania     1992    Landslide        333
Albania     1994     Storm           555
...
Albania     2014    Epidemic         5675

Note that now the the total casualties in "Afghanistan 1990 Flood" is the sum of the same disaster type occurred twice in Afghanistan in the same year (the same in Albania 1992 landslide). How can I obtain this?

Any help is highly appreciated.

 

 

2 REPLIES 2
Kurt_Bremser
Super User

Maxim 7: There Is a Procedure for It.

proc summary data=have nway;
class country year disaster_type;
var total_casualties;
output out=want (drop=_type_) sum()=;
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
  • 2 replies
  • 412 views
  • 0 likes
  • 3 in conversation