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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 254 views
  • 0 likes
  • 3 in conversation