<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I assign a Y/N indicator for patients having visited their &amp;quot;home&amp;quot; hospital? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967639#M376411</link>
    <description>&lt;P&gt;It sounds like you have to compute the distance between a patients home and all 200 hospitals to determine which one is closest. I imagine you would create an array to loop over all 200 hospitals and you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1korpfg2e18lon1nwpow9qijdxe.htm" target="_self"&gt;GEODIST function&lt;/A&gt; to compute the distance. Then assign a 1 if the patient actually visited the closest hospital and a 0 if the patient did not visit the closest hospital.&lt;/P&gt;</description>
    <pubDate>Wed, 28 May 2025 18:30:09 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-05-28T18:30:09Z</dc:date>
    <item>
      <title>How do I assign a Y/N indicator for patients having visited their "home" hospital?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967617#M376408</link>
      <description>&lt;P&gt;I'm working on a geocoding project to geocode resident and hospital addresses given patient hospital records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to first estimate the distance between the home and hospital addresses (pretty straightforward), then also assign a new Y/N indicator variable to each patient so I can identify them as having visited the hospital that is&amp;nbsp;&lt;EM&gt;closest&lt;/EM&gt; to their home address. There are approximately 5,000 rows, one for each patient, and about 200 hospitals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each row, I basically want SAS to scan through the hospitals, select the one that is closest in distance to the home address, compare that hospitals ID number to the one on the patient's record, and return a yes/no based on if those hospital IDs match.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I do this efficiently?&amp;nbsp; I currently have variable names &lt;STRONG&gt;X&lt;/STRONG&gt; and &lt;STRONG&gt;Y&lt;/STRONG&gt; for home address coordinates,&amp;nbsp;&lt;STRONG&gt;X_Hosp&lt;/STRONG&gt; and &lt;STRONG&gt;Y_Hosp&lt;/STRONG&gt; for the hospital addresses; this information is all in the same dataset and already assigned to each blinded patient &lt;STRONG&gt;ID&lt;/STRONG&gt;. But as I've worked, I've also kept copies of the datasets (PTS and HOSP) as they were before I merged them, so there is still a dataset with only the 200 hospitals that I can work with.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 17:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967617#M376408</guid>
      <dc:creator>SAS93</dc:creator>
      <dc:date>2025-05-28T17:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a Y/N indicator for patients having visited their "home" hospital?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967639#M376411</link>
      <description>&lt;P&gt;It sounds like you have to compute the distance between a patients home and all 200 hospitals to determine which one is closest. I imagine you would create an array to loop over all 200 hospitals and you can use the &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/n1korpfg2e18lon1nwpow9qijdxe.htm" target="_self"&gt;GEODIST function&lt;/A&gt; to compute the distance. Then assign a 1 if the patient actually visited the closest hospital and a 0 if the patient did not visit the closest hospital.&lt;/P&gt;</description>
      <pubDate>Wed, 28 May 2025 18:30:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967639#M376411</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-05-28T18:30:09Z</dc:date>
    </item>
    <item>
      <title>Re: How do I assign a Y/N indicator for patients having visited their "home" hospital?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967674#M376413</link>
      <description>&lt;P&gt;Pretty simplistic, but you could do this.&amp;nbsp; I wouldn't recommend this with anything much larger than what you have -- in your data, the CROSS JOIN will produce a table with 1M rows (5000*200), which is fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pt;
do pt=1 to 20;
	visited_hosp=rand('integer',1,10);
	X=rand('erlang',2)*5;
	Y=rand('erlang',2)*10;
	output;
end;
run;

data hosp;
do hospid=1 to 10;
	hosp_X=rand('erlang',2)*5;
	hosp_Y=rand('erlang',2)*10;
	output;
end;
run;

proc sql;
create table pthosp as
select a.*, b.hospid, 
geodist(a.Y, a.X, b.hosp_Y, b.hosp_X) as dist
from
	pt A
	cross join 
	hosp B
order by a.pt, dist;
quit;

data want;
set pthosp;
by pt;
if first.pt;
hosp_match='N';
if visited_hosp=hospid then hosp_match='Y';
run;

proc print data=want; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 29 May 2025 01:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-assign-a-Y-N-indicator-for-patients-having-visited/m-p/967674#M376413</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-05-29T01:05:06Z</dc:date>
    </item>
  </channel>
</rss>

