BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dil
Calcite | Level 5 Dil
Calcite | Level 5

Hi all,

 

I am working on a dataset with admission data, which includes each hospital/facility a patient was admitted to before he is admitted to a rehab facility. The acute site is VGH and rehab site is GFS. I would like to count how many patients went directly from VGH to GFS and how many of them had an indirect admission (there were some admissions to other hospitals before they were admitted to GFS). Below is a simple dataset for illustration. Even though it is very easy to see if the admission was direct or indirect when I look at the admission records for each patient, I find it a bit hard to code it in SAS. Any suggestions would be appreciated. 

 

PT ID     FACILITY    DIRECT

1               VGH         YES         

1               GFS

2               VGH          NO

2                 A

2                GFS

3                VGH         NO

3                 B

3                GFS

 

Thanks,

D

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

Does every first one of each group is VGH       ?

Does GFS always appear in each group ?

 

CODE NOT TESTED.

 

data want;

 merge have have(keep=PTID     FACILITY  rename=(PTID=_P    FACILITY=_F) firstobs=2);

 if PTID=_P and FACILITY='VGH' and _F='GFS' then DIRECT='YES';

 else DIRECT='NO ';

run;

 

View solution in original post

2 REPLIES 2
Ksharp
Super User

Does every first one of each group is VGH       ?

Does GFS always appear in each group ?

 

CODE NOT TESTED.

 

data want;

 merge have have(keep=PTID     FACILITY  rename=(PTID=_P    FACILITY=_F) firstobs=2);

 if PTID=_P and FACILITY='VGH' and _F='GFS' then DIRECT='YES';

 else DIRECT='NO ';

run;

 

Dil
Calcite | Level 5 Dil
Calcite | Level 5

Not every first row is VGH and yes GFS appear in each group although not necessarily the very last record for each PT. The logic/intuition you provided actually helpmed me solve the problem. Thanks for your help. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 902 views
  • 0 likes
  • 2 in conversation