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

Hello! I am studying hospital admissions and readmissions and am trying to figure out how to concatenate two variables so that SAS creates the same value of the variable whether the patient was admitted first to hospital A then hospital B, or first to hospital B then A.

 

The best (clumsy) way I could come up with was to concatenate admission hospital-readmission hospital and then readmission hospital-admission hospital variables in different data sets, merge them, and then add their counts. The issue with this is that I am then double counting admissions. Thanks!

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Sort them alphabetically first, assuming that names will be identical. Using that rule the two same hospitals should always appear in the same order. I also upcased them, and you may need compress/trim if the names are not 100% identical each time.

HospitalStart = upcase(Hospital1);
HospitalEnd = upcase(Hospital2);
call sortc(HospitalStart, HospitalEnd);
want = catx("-", HospitalStart, HospitalEnd);

You could probably nest those in some fashion but I spelled it out so it's clear how it works.

 

data have;
input admissionhospid $ readmissionhospid $ ;
cards;
A                           B
B                           A
A                           C
B                           C
;;;;
run;

data want;
set have;

HospitalStart = upcase(admissionhospid);
HospitalEnd = upcase(readmissionhospid);
call sortc(HospitalStart, HospitalEnd);
option1 = catx("-", HospitalStart, HospitalEnd);

if admissionhospid < readmissionhospid then option2 = catx("-", admissionhospid, readmissionhospid );
else option2 = catx("-", readmissionhospid, admissionhospid );


run;

Results:

 

Obs	admissionhospid	readmissionhospid	HospitalStart	HospitalEnd	option1	option2
1	A	B	A	B	A-B	A-B
2	B	A	A	B	A-B	A-B
3	A	C	A	C	A-C	A-C
4	B	C	B	C	B-C	B-C

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

Can you show us a portion of the data you are using, and the desired output?

--
Paige Miller
saraturbow
Calcite | Level 5

Yes--hope this snapshot helps. Each line of data is an admission-readmission dyad and I am trying to determine the number of admissions to each pair of hospitals. When I concatenate the admissionhospid and readmissionhospid and count their frequencies, 'AB' and 'BA' are counted separately, but I would like them to be counted together.

admissionhospid  readmissionhospid

A                           B

B                           A

A                           C

B                           C

Reeza
Super User
Updated my answer, to use your sample data.
Reeza
Super User

Sort them alphabetically first, assuming that names will be identical. Using that rule the two same hospitals should always appear in the same order. I also upcased them, and you may need compress/trim if the names are not 100% identical each time.

HospitalStart = upcase(Hospital1);
HospitalEnd = upcase(Hospital2);
call sortc(HospitalStart, HospitalEnd);
want = catx("-", HospitalStart, HospitalEnd);

You could probably nest those in some fashion but I spelled it out so it's clear how it works.

 

data have;
input admissionhospid $ readmissionhospid $ ;
cards;
A                           B
B                           A
A                           C
B                           C
;;;;
run;

data want;
set have;

HospitalStart = upcase(admissionhospid);
HospitalEnd = upcase(readmissionhospid);
call sortc(HospitalStart, HospitalEnd);
option1 = catx("-", HospitalStart, HospitalEnd);

if admissionhospid < readmissionhospid then option2 = catx("-", admissionhospid, readmissionhospid );
else option2 = catx("-", readmissionhospid, admissionhospid );


run;

Results:

 

Obs	admissionhospid	readmissionhospid	HospitalStart	HospitalEnd	option1	option2
1	A	B	A	B	A-B	A-B
2	B	A	A	B	A-B	A-B
3	A	C	A	C	A-C	A-C
4	B	C	B	C	B-C	B-C
saraturbow
Calcite | Level 5
Thank you! Will try this!
ballardw
Super User

Readmission frequently happens more than once and admission may as well over time.

So you need to provide some pretty clear rules about which are initial admissions and which re-admissions might be associate with a specific admission.

 

I suspect that date information may be helpful but examples are needed to provide good workable approaches.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 590 views
  • 4 likes
  • 4 in conversation