BookmarkSubscribeRSS Feed
alsi21ac
Calcite | Level 5

Hi all, 

I have a dataset that looks approximately like this

Country       year   Dis_type           type_extreme_temp    type_flood

Afghanistan 1990   Extreme temp              1                                 0

Afghanistan 1990   Flood                            0                                1

Afghanistan 1992   Extreme temp              1                                 0

...

Albania        1991   Extreme temp              1                                 0

Albania        1991   Flood                            0                                 1

...

 

and I would like to obtain a dataset that looks like this:

 

Country       year      type_extreme_temp    type_flood

Afghanistan 1990                   1                                 1

Afghanistan 1992                   1                                 0

...

Albania        1991                   1                                 1

...

 

i.e. I would like to group in the same observation all the disasters occurred in a given year (type_extreme_temp and type_flood are dummies =1 if that type of disaster occurred at least once in that year).

I tried by using proc sort but I didn't succeed. 

Any help would be highly appreciated.

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

This is a job for PROC SUMMARY

 

proc summary data=have nway;
    class country year;
    var type_extreme_temp type_flood;
    output out=want sum=;
run;
--
Paige Miller
Reeza
Super User

Do you want the summary to be the number of events or just 1/0 again? If 1/0 summarize to MAX statistic.

 

proc means data=have nway  MAX stackods;
    class country year;
    var type_extreme_temp type_flood;
    output out=want max=;
run;

@alsi21ac wrote:

Hi all, 

I have a dataset that looks approximately like this

Country       year   Dis_type           type_extreme_temp    type_flood

Afghanistan 1990   Extreme temp              1                                 0

Afghanistan 1990   Flood                            0                                1

Afghanistan 1992   Extreme temp              1                                 0

...

Albania        1991   Extreme temp              1                                 0

Albania        1991   Flood                            0                                 1

...

 

and I would like to obtain a dataset that looks like this:

 

Country       year      type_extreme_temp    type_flood

Afghanistan 1990                   1                                 1

Afghanistan 1992                   1                                 0

...

Albania        1991                   1                                 1

...

 

i.e. I would like to group in the same observation all the disasters occurred in a given year (type_extreme_temp and type_flood are dummies =1 if that type of disaster occurred at least once in that year).

I tried by using proc sort but I didn't succeed. 

Any help would be highly appreciated.

 


 

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
  • 527 views
  • 2 likes
  • 3 in conversation