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;

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
  • 2 replies
  • 635 views
  • 0 likes
  • 3 in conversation