BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ihsan-Mahdi
Quartz | Level 8

Hello,

 

I have a set with hospital IDs, names, and addresses. In the same set the same hospital could be the place for patient admission, patient referral (patient sent to another hospital), or patient reception (patient came from another hospital). The address is assigned only to the admission hospital.

Is there a quick way/code to create referring hospital and receiving hospital address variables  using the hospital ID and Address fields? 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@Ihsan-Mahdi wrote:

Just wondering, is there a way that involves creating new variables?


Sure. Once you've got the format created you can use it to populate a new variable in a data step using code like: 

Referring_Hx_addr=put(Referring_Hx_ID, hospital_name.);

 

View solution in original post

13 REPLIES 13
PaigeMiller
Diamond | Level 26

@Ihsan-Mahdi wrote:

 

Is there a quick way/code to create referring hospital and receiving hospital address variables  using the hospital ID and Address fields? 


I think the answer is YES, but without seeing example data and example desired output, I don't think I can write such code. If the information is confidential, you can make up hospital names and addresses, as long as the data set and desired output illustrates the actual problem.

--
Paige Miller
Ihsan-Mahdi
Quartz | Level 8

Thanks for offering to help! I think the tables below best describe (to me at least 😄) what I have and what I want:

 

HAVE
Obs Hospital ID Hospital Name (where patient currently is) Address Referring Hx ID Receiving Hx ID
1 8 A 310 S X Ave . 3
2 99 B 31 Y Ave . 4
3 102 C 45 D Ave 5 .
4 37 D 63 E Ave 6 .

 

 

WANT
Obs Hospital ID Hospital Name (where patient currently is) Address Referring Hx ID Ref Hx Address Receiving Hx ID Rec Hx Address
1 8 A 310 S X Ave .   3  
2 99 B 31 Y Ave .   4  
3 102 C 45 D Ave 5   .  
4 37 D 63 E Ave 6   .  
PaigeMiller
Diamond | Level 26

In row 1, the receiving hospital ID is 3. How would we know what the address of hospital 3 is?

--
Paige Miller
Ihsan-Mahdi
Quartz | Level 8

The Hospital ID is the same for each hospital regardless of it being admitting, referring, or receiving. So, a receiving hospital ID (3) in one record, and a referring hospital ID (3) in another record would be the same hospital but being a different place for a different patient. Each observation is a patient record.

PaigeMiller
Diamond | Level 26

@Ihsan-Mahdi wrote:

The Hospital ID is the same for each hospital regardless of it being admitting, referring, or receiving. So, a receiving hospital ID (3) in one record, and a referring hospital ID (3) in another record would be the same hospital but being a different place for a different patient. Each observation is a patient record.


I'm afraid this does not answer my question which was: How would we know what the address of hospital 3 is?

--
Paige Miller
Patrick
Opal | Level 21

Below one way how to go about this that avoids creation of additional variables. 

In your sample data you don't provide an address for all hospital IDs and though you will only get formatted values for the IDs where there is somewhere in your data a matching address.

data have;
  infile datalines truncover dlm='|' dsd;
  input obs Hospital_ID Hospital_Name$ Address:$40. Referring_Hx_ID Receiving_Hx_ID;
  datalines;
1|8|A|310 S X Ave|.|3
2|99|B|31 Y Ave|.|102
3|102|C|45 D Ave|5|.
4|37|D|63 E Ave|6|.
;

proc sql;
  create view v_hospital_addresses as
  select distinct
    'hospital_name' as fmtname,
    'n' as type,
    Hospital_ID as start,
    address as label
  from have
  ;
quit;

proc format cntlin=v_hospital_addresses;
run;

proc print data=have;
  format hospital_id Referring_Hx_ID Receiving_Hx_ID hospital_name.;
run;

Patrick_0-1708645298954.png

 

 

Ihsan-Mahdi
Quartz | Level 8
Thank you so much. I will try this and let you know. Really appreciate it!
Patrick
Opal | Level 21

@Ihsan-Mahdi wrote:
Thank you so much. I will try this and let you know. Really appreciate it!

Just as a feedback:

I've spent more than half of my time for converting your table with sample data to a SAS data step have that creates the data. 

If you want to help us help you then going forward please provide sample data via SAS code that creates the data same as I've done it in my data have step.

Ihsan-Mahdi
Quartz | Level 8
Will do. Sorry for the inconvenience and thanks again.
Ihsan-Mahdi
Quartz | Level 8

Just wondering, is there a way that involves creating new variables?

Patrick
Opal | Level 21

@Ihsan-Mahdi wrote:

Just wondering, is there a way that involves creating new variables?


Sure. Once you've got the format created you can use it to populate a new variable in a data step using code like: 

Referring_Hx_addr=put(Referring_Hx_ID, hospital_name.);

 

Ihsan-Mahdi
Quartz | Level 8
Excellent! Thank you!
Patrick
Opal | Level 21

If you've got in your data the hospital IDs for patient admission, patient referral and patient reception then it's a simple lookup.

To provide code we would need sample data that's representative for your real data (please share via SAS data step code that creates such data).

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 13 replies
  • 1959 views
  • 1 like
  • 3 in conversation