I am trying to write a sas code based on the following the below two conditions with given datasets (CE, FA, AE).
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;
This code is good and seems to do what you want.
You should use the running man icon to post code.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.