BookmarkSubscribeRSS Feed
Juls_Mung
Calcite | Level 5

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
    1. (CE.CECAT = ‘MYOCARDIAL INFARCTION’ ) and
    2. (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;

1 REPLY 1
ChrisNZ
Tourmaline | Level 20

This code is good and seems to do what you want.


You should use the running man icon to post code.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 289 views
  • 0 likes
  • 2 in conversation