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:
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;But how can I turn this into a loop to go through multiple values if I had a list like the following:
data ndc;
input ndc $11.;
datalines;
00002140701
00002143361
;
run;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.
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.
Then turn it into a macro.
https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md
@A_SAS_Man wrote:
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:
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;But how can I turn this into a loop to go through multiple values if I had a list like the following:
data ndc; input ndc $11.; datalines; 00002140701 00002143361 ; run;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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.