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.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.