I have two datasets. Dataset1: age_event variable is the age at which each ID reported an event. IDs that did not reported events were not included in this dataset. data ds1;
input ID age_event;
datalines;
a1 67
b2 89
b3 3
d2 0
;
run; Dataset2: All IDs of the sample are reported. this dataset contains one row per ID. variable "last_agerecorded" is the at which each reported their last record. data main;
input ID last_agerecorded;
datalines;
a1 56
a2 67
b1 68
b2 72
b3 132
c2 121
c3 124
c4 58
d1 89
d2 95
e2 74
;
run; We would like to create an "event" variable that equals to 1 if the event was reported and the corresponding age reported on "age_event". This is from dataset ds1. If an ID did not report an event, then event=0, and "age_event" should be equal to the age under "age_lastrecorded" from the dataset main. How can we get the required output below? Thank you. ID age_event event a1 67 1 a2 67 0 b1 68 0 b2 89 1 b3 3 1 c2 121 0 c3 124 0 c4 58 0 d1 89 0 d2 0 1 e2 74 0
... View more