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
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;
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;
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.
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.
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.