Hi all, I have a data set created with the following code: data test; input id $ dxday caetype $; datalines; 01 1890 NONSP 01 2120 INFL 01 2128 INFL 01 2135 INFL 01 2137 NONSP 02 -775 INFL 02 -569 NONSP 03 3020 ARR 03 3026 NONSP 03 3027 NONSP 03 3175 INFL ; run; The 3 variables denote patient ID number, number of days the patient experienced a cardiac adverse event (CAE) relative to a certain vaccination, and type of CAE. I'm trying to calculate differences in the number of days from a baseline value for each patient, where the baseline value is the first occurrence of a CAE with type 'INFL'. So, for ID 01, the first INFL CAE occurs at the 2nd observation (dxday=2120); for ID 02, the first INFL CAE occurs at the 1st observation (dxday=-775); and for ID 03 the first INFL CAE occurs at the last observation (dxday=3175). What I'd like to do is to create a difference variable (DIFF) that calculates time differences based on the correctly identified baseline time value for each patient. So, what I'd like to end up with is a data set that looks like this: id dxday caetype DIFF 01 1890 NONSP -230 01 2120 INFL 0 01 2128 INFL 8 01 2135 INFL 15 01 2137 NONSP 17 02 -775 INFL 0 02 -569 NONSP 206 03 3020 ARR -155 03 3026 NONSP -149 03 3027 NONSP -148 03 3175 INFL 0 Can anyone provide any insight on how to do this? Thanks so much! chucsp
... View more