10-31-2017 04:11 PM
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.
in case you need to know, they are merging by caseid year psu .
10-31-2017 04:17 PM
10-31-2017 06:52 PM
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;