<?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: Difficulties using macro with variables and storing results in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898781#M43846</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;How can I make sure to get the results without changing manually the coordinates everytime?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Since your latitude/longitude coordinates are in a SAS data set, you could use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1q1527d51eivsn1ob5hnz0yd1hx.htm" target="_self"&gt;CALL EXECUTE&lt;/A&gt; to call the macro using values in the data set. There are examples at the link of extracting data from a database that can be used in macro call.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2023 13:22:22 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-16T13:22:22Z</dc:date>
    <item>
      <title>Difficulties using macro with variables and storing results</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898780#M43845</link>
      <description>&lt;P&gt;Hello SAS Experts!&lt;/P&gt;&lt;P&gt;I'm having some trouble using MACRO, I can't figure it out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with the following variables: subject_ID, latitude, longitude&lt;/P&gt;&lt;P&gt;and another dataset with: hospital_id, hospital_lat, hospital_lon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let's pretend this is my dataset with the subjects:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;subject_ID&lt;/TD&gt;&lt;TD&gt;latitude&lt;/TD&gt;&lt;TD&gt;longitude&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;10.15&lt;/TD&gt;&lt;TD&gt;45.73&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;10.25&lt;/TD&gt;&lt;TD&gt;45.83&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;10.35&lt;/TD&gt;&lt;TD&gt;45.93&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;10.45&lt;/TD&gt;&lt;TD&gt;46.03&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;10.55&lt;/TD&gt;&lt;TD&gt;46.13&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And this is the on with the hospitals:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;hospital_id&lt;/TD&gt;&lt;TD&gt;hospital_lat&lt;/TD&gt;&lt;TD&gt;hospital_lon&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10.65&lt;/TD&gt;&lt;TD&gt;46.23&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;10.75&lt;/TD&gt;&lt;TD&gt;46.33&lt;/TD&gt;&lt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;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do that, I tried using a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;%MACRO distance(lat1, lon1);

filename filejsn "P:\Folder\macro.json" lrecl = 32000;

proc http
method="POST"
url="https://api.openrouteservice.org/v2/directions/driving-car/json"
ct="application/json"
oauth_bearer="5b3ce3597851110001cf6248da7564cd409644daae4f2eafdc8f3662"
in="{""coordinates"": [[&amp;amp;lat1,&amp;amp;lon1],[10.65, 46.23]] }"
out = filejsn;
run;

libname mac JSON fileref= filejsn;

data dist; set mac.routes_summary; 

%MEND distance;

%distance(lat1 = 10.15, lon1 = 45.73);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output data dist gives me the distance between the first subject and the first hospital, exactly what I'm looking for!&lt;/P&gt;&lt;P&gt;How can I make sure to get the results without changing manually the coordinates everytime?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you a lot for your collaboration!&lt;BR /&gt;I'm using SAS Enterprise Guide, 9.4M6 release&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 13:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898780#M43845</guid>
      <dc:creator>veronicasalmaso</dc:creator>
      <dc:date>2023-10-16T13:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulties using macro with variables and storing results</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898781#M43846</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;How can I make sure to get the results without changing manually the coordinates everytime?&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Since your latitude/longitude coordinates are in a SAS data set, you could use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1q1527d51eivsn1ob5hnz0yd1hx.htm" target="_self"&gt;CALL EXECUTE&lt;/A&gt; to call the macro using values in the data set. There are examples at the link of extracting data from a database that can be used in macro call.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 13:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898781#M43846</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-16T13:22:22Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulties using macro with variables and storing results</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898793#M43847</link>
      <description>&lt;P&gt;This looks like an all combinations join, where this would do the trick:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table want as select * from subjects, hospitals;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No macro language needed.&amp;nbsp; You just need to begin with the two SAS data sets you describe as the inputs.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 14:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898793#M43847</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-10-16T14:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulties using macro with variables and storing results</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898823#M43851</link>
      <description>1. Cross join table to get all location information in one table.&lt;BR /&gt;2. Redesign macro to take both locations as parameters (not just &amp;amp;lat1, &amp;amp;lon1) and the ID (hospital and subject) as well. &lt;BR /&gt;3. Modify macro to append results to a master table, including the IDs&lt;BR /&gt;4. Use CALL EXECUTE to call the macro for each line in table 1.&lt;BR /&gt;5. Ensure that the output is dropped before each run to avoid duplicate results. &lt;BR /&gt;6. If your datasets are large, you can add some filters using the flying distance  before you call the API for the driving distance using geodist() function.</description>
      <pubDate>Mon, 16 Oct 2023 15:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898823#M43851</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-16T15:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Difficulties using macro with variables and storing results</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898831#M43855</link>
      <description>&lt;P&gt;I worked through a very similar exercise in this thread:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Find-driving-distance-google-maps-usinga-list-of-10-hospital/m-p/884611&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It basically implements the approach that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;listed.&amp;nbsp; Since you've already got a version of the simple macro working, you should be able to use that post as an example of one way to extend it to work for multiple patients and multiple hospitals.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2023 17:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Difficulties-using-macro-with-variables-and-storing-results/m-p/898831#M43855</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-10-16T17:21:22Z</dc:date>
    </item>
  </channel>
</rss>

