BookmarkSubscribeRSS Feed
robertrao
Quartz | Level 8

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

4 REPLIES 4
ballardw
Super User

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?

robertrao
Quartz | Level 8
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
Amir
PROC Star

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.

Mit
Calcite | Level 5 Mit
Calcite | Level 5

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=_:)  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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1445 views
  • 0 likes
  • 4 in conversation