If your data are sorted by year, and then data set is large, then this code is likely faster. It depends on reading each year of data twice, the first to build a hash object (think "lookup table"), and the second pass to reread the same year, and compute the joint_possibility and joint_probability: At the end of processing for that year, the hash object is emptied, and ready for the next year.
data want (keep=year joint_possibility joint_probability) ;
set have (in=firstpass) have (in=secondpass);
by year;
if _n_=1 then do;
if 0 then set have (rename=(year=_year event=_event outcome=_outcome prob=_prob));
declare hash evts(ordered:'a') ;
evts.definekey('_event','_outcome');
evts.definedata('_event','_outcome','_prob');
evts.definedone();
declare hiter e ('evts');
end;
if firstpass then evts.add(key:event,key:outcome,data:event,data:outcome,data:prob);
if secondpass then do while (e.next()=0);
if _event<=event then continue;
length joint_possibility $20;
joint_possibility = catx('*',outcome,_outcome);
joint_probability = prob*_prob;
output;
end;
if last.year then evts.clear();
run;
... View more