BookmarkSubscribeRSS Feed
A_SAS_Man
Pyrite | Level 9

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.

2 REPLIES 2
Reeza
Super User

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.



 

A_SAS_Man
Pyrite | Level 9
Thank you that is a great resource.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 901 views
  • 0 likes
  • 2 in conversation