I am trying to write a sas code based on the following the below two conditions with given datasets (CE, FA, AE). Investigator-reported MI defined as subjects with (CE.CECAT = ‘MYOCARDIAL INFARCTION’ ) and (FA.FAORRES in (‘STEMI’,’NSTEMI’) when FA.FAOBJ="TYPE OF SUSPECTED CARDIAC ISCHEMIC EVENT" and FA.FASCAT= "TYPE OF SUSPECTED CARDIAC ISCHEMIC EVENT" and FA.FACAT = 'MYOCARDIAL INFARCTION'). This means that, for those subjects with missing FAORRES, if their PT (AE.AEDECOD) = ‘ACUTE MYOCARDIAL INFARCTION’, we set FAORRES as ‘STEMI’ and treat them as investigator-reported MI. All other missing FAORRES are treated as non-MI. Below is my attempt to writing the program code based on the logic of my understanding of the two conditions. I really would like to have a review and better sas programming code for my request. ################ My code ################################### /* Merge CE, FA, and AE datasets and filter relevant CECAT values */ proc sql; create table merged_wce as select a.*, b.faorres, b.faobj, b.fascat, b.facat, c.aedecod from sdtmp.ce as a left join sdtmp.fa as b on a.usubjid = b.usubjid left join sdtmp.ae as c on a.usubjid = c.usubjid where a.cecat in ('MYOCARDIAL INFARCTION', 'MAJOR ADVERSE LIMB EVENT', 'SUSPECTED CEREBROVASCULAR ISCHEMIC EVENT'); quit; /* Update FAORRES based on AEDECOD if missing, and apply final filters */ data wce_m (where=(cecat in ('MYOCARDIAL INFARCTION','MAJOR ADVERSE LIMB EVENT','SUSPECTED CEREBROVASCULAR ISCHEMIC EVENT') & faorres in ('STEMI', 'NSTEMI'))); set merged_wce; /* Impute FAORRES if missing */ if missing(faorres) then do; if aedecod = 'Acute myocardial infarction' then faorres = 'STEMI'; else faorres = 'Non-MI'; end; /* Apply filtering criteria */ if cecat = 'MYOCARDIAL INFARCTION' & faorres in ('STEMI', 'NSTEMI') & faobj = 'TYPE OF SUSPECTED CARDIAC ISCHEMIC EVENT' & fascat = 'TYPE OF SUSPECTED CARDIAC ISCHEMIC EVENT' & facat = 'MYOCARDIAL INFARCTION'; run;
... View more