Help using Base SAS procedures

SAS Question on Flagging

Reply
Super Contributor
Posts: 1,040

SAS Question on Flagging

Hi,

I have the following scenarios.

PAT is the patient

ENC is the encounter ID 's for that patient

CNT is the count of the number of encounters

EM is emergency flag

IP is Inpatient flag

OP is Outpatient flag

We are trying to see if the EM encounters turned to IP or OP or DISCHARGE based on the flags

If they have EM=1 and IP=0 and OP=0 then that means they are discharged from EM directly

I have presented cases how to flag if present as a single record or multiple records and the three scenarios

PAT    ENC   ADMIT               CNT     EM      IP   OP

101     001     8/28/2013            1         1          1    0  ----------->EM to IP
or
101     001     8/28/2013               1          1         0    0.....................>EM to IP
101     001    8/28/2013                2          0        1    0 (admitted in EM and in the same encounter(seen here by the same ENC) they are discharged from IP
101      001      8/28/2013               1           1          0   1.....................>EM to OP
or
101     001    8/28/2013                  1            1         0    0.....................>EM to OP
101     002    8/28/2013                 2             0         0    1
101      001      8/28/2013               1           1          0   0.....................>EM to DISCHARGE
or
101     001    8/28/2013                  1            1         0    0.....................>EM to DISCHARGE
101     002    8/28/2013                 2             0         0    0
Thanks

Super User
Posts: 10,500

Re: SAS Question on Flagging

robertrao wrote:

PAT    ENC   ADMIT               CNT     EM      IP   OP

101     001     8/28/2013               1          1         0    0.....................>EM to IP
101     001    8/28/2013                  1            1         0    0.....................>EM to OP
101      001      8/28/2013               1           1          0   0.....................>EM to DISCHARGE

I don't see the difference between these records that indicate a different outcome. Are you looking to create code that says they were treated differently or 3 codes indicating 3 outcomes? What is the desired output?

Super Contributor
Posts: 1,040

Re: SAS Question on Flagging

Hi Ballard,
Thanks for the reply...
i changed a little bit......i changed the PAT numbers
and each of them can have one or more of these scenarios
Thanks
PAT    ENC   ADMIT               CNT     EM      IP   OP
101     001     8/28/2013            1         1          1    0  ----------->EM to IP
or
101     001     8/28/2013               1          1         0    0.....................>EM to IP
101     001    8/28/2013                2          0        1    0 (admitted in EM and in the same encounter(seen here by the same ENC) they are discharged from IP
102      001      8/28/2013               1           1          0   1.....................>EM to OP
or
102     001    8/28/2013                  1            1         0    0.....................>EM to OP
102     002    8/28/2013                 2             0         0    1
103      001      8/28/2013               1           1          0   0.....................>EM to DISCHARGE
or
103    001    8/28/2013                  1            1         0    0.....................>EM to DISCHARGE
103     002    8/28/2013                 2             0         0    0
Super Contributor
Posts: 282

Re: SAS Question on Flagging

Hi,

How about:

data want;

  set have;

  by pat enc;

  length result $9;

 

  if last.enc;

  if ip then

    result='IP';

  else

    if op then

      result='OP';

    else

      result='DISCHARGE';

run;

If it is not what you then please provide the required output records and also what should happen if EM is never 1 for a patient or is that not possible?

Regards,

Amir.

Frequent Contributor
Frequent Contributor
Posts: 83

Re: SAS Question on Flagging

How about the following code

data have ;
set have;
count=1;
run;
proc sort data=have;
by PAT    ENC   ADMIT  ;
run;
proc summary data=have missing nway;
by PAT    ENC   ADMIT  ;
var EM    IP   OP count;
output out=want(drop=_Smiley Happy  sum=;
run;

data want;
set want;
format result $20.;
     if EM=1 then do;
          if IP=1 and OP=0 then result='EM to IP';
          else if IP=1 and OP=1 then result='IP to OP';
          else if IP=0  and OP=1 then result='EM to OP';
          else if IP=0  and OP=0 then result='EM to DISCHARGE';
     end;
run;

proc sort data=want out=want1(keep=PAT    ENC   ADMIT  result);
by PAT    ENC   ADMIT ;
run;


data final;
merge have(in=a) want1(in=b);
     by PAT    ENC   ADMIT ;
     if a;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 247 views
  • 0 likes
  • 4 in conversation