<?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: looop through postalcodes in table and get api response in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/looop-through-postalcodes-in-table-and-get-api-response/m-p/878381#M347036</link>
    <description>&lt;P&gt;Hi, I've done this in the past using DS2 instead of the DataStep. This uses the HTTP package in DS2 instead of PROC HTTP. There's a really nice example with code by Chris Hemedinger here:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 May 2023 09:35:39 GMT</pubDate>
    <dc:creator>HarrySnart</dc:creator>
    <dc:date>2023-05-31T09:35:39Z</dc:date>
    <item>
      <title>looop through postalcodes in table and get api response</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looop-through-postalcodes-in-table-and-get-api-response/m-p/878369#M347026</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a table called input containing postalcodes, housenumbers, and housenumber additions. I want to look up all these combinations in an API and receive the response back in the input table. I am able to retrieve the result for one row in the table, but not for multiple rows. Additionally, some addresses have house number additions, which means the URL changes. Who can assist me further?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An example of my input table:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;postalCode&amp;nbsp;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;streetNumber&lt;/TD&gt;
&lt;TD&gt;streetNumberAddition&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1234AB&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;2345CD&lt;/TD&gt;
&lt;TD&gt;8&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;if 0 then set work.input nobs=nobs; /* deze regel haalt het aantal rijen op */&lt;BR /&gt;call symputx('cnt', nobs); /* sla het aantal rijen op in de macrovariabele 'cnt' */&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%let api_key = 123456;&lt;/P&gt;
&lt;P&gt;/* Stap 3: Definieer de macro voor de API-loop */&lt;BR /&gt;%macro APILoop();&lt;BR /&gt;%do i = 1 %to &amp;amp;cnt.;&lt;BR /&gt;/* Stap 4: Haal de variabelen op voor de huidige iteratie */&lt;BR /&gt;data _null_;&lt;BR /&gt;set input (obs=&amp;amp;i.); /* haal alleen de huidige rij op */&lt;BR /&gt;call symputx('streetNumber', streetNumber);&lt;BR /&gt;call symputx('postalCode', postalCode);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/* Stap 5: Bouw de URL op met de juiste variabelen */&lt;BR /&gt;%let base_url = %nrstr;&lt;BR /&gt;%let new_url = &amp;amp;base_url.&amp;amp;%nrstr(&amp;amp;streetNumber=)&amp;amp;streetNumber&amp;amp;%nrstr(&amp;amp;postalCode=)&amp;amp;postalCode&amp;amp;limit=10&amp;amp;offset=0;&lt;/P&gt;
&lt;P&gt;/* Stap 6: Voer de HTTP-aanroep uit */&lt;BR /&gt;proc http&lt;BR /&gt;method='GET'&lt;BR /&gt;url="&amp;amp;new_url"&lt;BR /&gt;proxyhost="hidden" proxyport=hidden&lt;BR /&gt;out=response;&lt;BR /&gt;headers "accept" = "application/json"&lt;BR /&gt;"X-API-Key" = "&amp;amp;api_key";&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;/* Stap 7: Verwerk de HTTP-respons */&lt;BR /&gt;data _null_;&lt;BR /&gt;infile response;&lt;BR /&gt;input;&lt;BR /&gt;put _infile_;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;libname response json;&lt;BR /&gt;proc copy in=response out=work;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;/* Stap 8: Voer de API-loop uit */&lt;BR /&gt;%APILoop();&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 11:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looop-through-postalcodes-in-table-and-get-api-response/m-p/878369#M347026</guid>
      <dc:creator>MADS1</dc:creator>
      <dc:date>2023-06-09T11:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: looop through postalcodes in table and get api response</title>
      <link>https://communities.sas.com/t5/SAS-Programming/looop-through-postalcodes-in-table-and-get-api-response/m-p/878381#M347036</link>
      <description>&lt;P&gt;Hi, I've done this in the past using DS2 instead of the DataStep. This uses the HTTP package in DS2 instead of PROC HTTP. There's a really nice example with code by Chris Hemedinger here:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/09/28/parse-json-from-sas/&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 09:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/looop-through-postalcodes-in-table-and-get-api-response/m-p/878381#M347036</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2023-05-31T09:35:39Z</dc:date>
    </item>
  </channel>
</rss>

