BookmarkSubscribeRSS Feed
UCFtigers2017
Fluorite | Level 6

I am looking for help with how to do what I believe is a many - to - one merge (if possible).

 

I have 2 data sets :

 

A. car crashes (each observation is a crash)

B. car vehicles involved in a crash (each observation is a car in one of the crashes in first data set)

 

I have an indicator called "distract" in data set B that determines whether the driver of that car was distracted while driving.

0 = not distracted

1 = distracted

 

I want a merge into data set A so that that the crash takes on the value of  1 if ANY of the cars involved in that crash had a distracted driver.  

 

Another way that could be acceptable, is the "distract" variable in the new merged set can take on the value of the SUM of distracted drivers involved in the crash.

 

Thanks!

 

in case you need to know, they are merging by caseid year psu .

2 REPLIES 2
Reeza
Super User
This is much easier if you provide sample data we can work with. But the concept is still the same, calculate a summary statistic and merge in with the full data. You may be able to do this summarizing the accident data to determine the number of distracted drivers per accident and then merging that summary data.
ballardw
Super User

Maybe something similar to:

proc sql;
   create table want as
   select a.*, max(b.distracted) as AnyDistracted,
          sum(b.Distracted) as TotalDistracted
   from crashset as a
        left join
        vehicleset a b
        on a.caseid=b.caseid
        and a.year =b.year
        and a.psu  =b.psu
  group by a.crashid,a.year,a.psu
  ;
quit; 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1039 views
  • 0 likes
  • 3 in conversation