<?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 Looping Through API Request in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565574#M158817</link>
    <description>&lt;P&gt;I am attempting to send multiple requests to an API and save all of the results appended in a datafile. I am able to successfully query the API and save one result with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp 'location/demo.json';

proc http
method="GET"
url="https://rxnav.nlm.nih.gov/REST/ndcstatus.json?ndc=00002140701"
out=resp;
run;

libname myfiles json 'location/demo.json';

data ndcstatus;
set myfiles.ndcstatus;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But how can I turn this into a loop to go through multiple values if I had a list like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ndc;
input ndc $11.;
datalines;
00002140701
00002143361
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have not worked with loops much before but what I'm trying to do is query the API, save the results, query again, append those results to the previous, etc for a long list of numbers.&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jun 2019 14:55:36 GMT</pubDate>
    <dc:creator>A_SAS_Man</dc:creator>
    <dc:date>2019-06-12T14:55:36Z</dc:date>
    <item>
      <title>Looping Through API Request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565574#M158817</link>
      <description>&lt;P&gt;I am attempting to send multiple requests to an API and save all of the results appended in a datafile. I am able to successfully query the API and save one result with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp 'location/demo.json';

proc http
method="GET"
url="https://rxnav.nlm.nih.gov/REST/ndcstatus.json?ndc=00002140701"
out=resp;
run;

libname myfiles json 'location/demo.json';

data ndcstatus;
set myfiles.ndcstatus;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But how can I turn this into a loop to go through multiple values if I had a list like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ndc;
input ndc $11.;
datalines;
00002140701
00002143361
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have not worked with loops much before but what I'm trying to do is query the API, save the results, query again, append those results to the previous, etc for a long list of numbers.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 14:55:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565574#M158817</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-06-12T14:55:36Z</dc:date>
    </item>
    <item>
      <title>Re: Looping Through API Request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565592#M158819</link>
      <description>&lt;P&gt;First, ensure that program is complete and stores the files you want in a location you want with the name you want. And that it cleans up after itself so you don't have a libname or data set hanging around to mess up your next steps.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then turn it into a macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/234586"&gt;@A_SAS_Man&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am attempting to send multiple requests to an API and save all of the results appended in a datafile. I am able to successfully query the API and save one result with the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename resp 'location/demo.json';

proc http
method="GET"
url="https://rxnav.nlm.nih.gov/REST/ndcstatus.json?ndc=00002140701"
out=resp;
run;

libname myfiles json 'location/demo.json';

data ndcstatus;
set myfiles.ndcstatus;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But how can I turn this into a loop to go through multiple values if I had a list like the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ndc;
input ndc $11.;
datalines;
00002140701
00002143361
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have not worked with loops much before but what I'm trying to do is query the API, save the results, query again, append those results to the previous, etc for a long list of numbers.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2019 15:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565592#M158819</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-12T15:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: Looping Through API Request</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565610#M158824</link>
      <description>Thank you that is a great resource.</description>
      <pubDate>Wed, 12 Jun 2019 16:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looping-Through-API-Request/m-p/565610#M158824</guid>
      <dc:creator>A_SAS_Man</dc:creator>
      <dc:date>2019-06-12T16:06:28Z</dc:date>
    </item>
  </channel>
</rss>

