BookmarkSubscribeRSS Feed
UdayGuntupalli
Quartz | Level 8

All, 
    I am trying to write multiple api calls using Proc HTTP in the same script. Is it possible to reuse Libname "in" after extracting the data I want from one api call to the next. My code looks like so : 

 

 

Filename Test1 "&WorkDir./ApiTest.txt";
Proc HTTP
	URL = &ProdUrlDes.
	Method = "get"
  	Out = Test1 ; 
Run;

* Assign Libname for parsing ; 
Libname in json "&WorkDir./ApiTest.txt";

* Parse JSON Response; 
Data Details;
	set in.root; 
Run; 
Proc Sql NoPrint; 
	Select Var1 Into :GlobalVar1 From Details; 
Quit;
Libname in clear; 

Filename ForResp  "&WorkDir./ApiForTest.txt";
Proc HTTP
	URL = &UrlTest. 
	Method = "get"
	Out = ForResp; 
Run;  

* Assign Libname for parsing ; 
Libname in json "&WorkDir./ApiForTest.txt";

* Parse JSON Response; 
Data SiteData;
	set in.root; 
Run; 

Libname in clear; 

I get the following errors: 

 

 

image.png

2 REPLIES 2
Tom
Super User Tom
Super User

Yes.

Your error message is complaining about what is actually in the JSON file and has nothing to do with "reusing" the libref.

Kurt_Bremser
Super User

Inspect the result of the proc http call ("&WorkDir./ApiForTest.txt") with a text editor. You might find some kind of message that you got back from the website instead of the expected JSON file.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 433 views
  • 2 likes
  • 3 in conversation