BookmarkSubscribeRSS Feed
Lost_Gary
Quartz | Level 8

I have an API that works just fine. However, when i attempt to call the API several times within a Macro, after about the 4th call of the API, I get a data error that the dataset is not found.  I've put it in a do loop and then more simply put it in code such as this:


%macro one(macvar);

filename rsi "\\mypath.json";
proc http
url="https://my API &macvar"
out=rsi;
run;
libname rsi json "\\mypath.json";

%mend;
%one(A);
%one(B);
%one(C);
%one(D);

when it gets to D, i receive an error that the data set 'Results_Values' does not exist.  wondering if i am hitting the API to many times to fast with the macro. If I run D on it's own it will work just fine. Has anyone else experienced this and is there a known workaround? I am using SAS Enterprise Guide 8.3. 

 

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Since you are having an error in code involving macros, please turn on the macro debugging option by running this command:

 

options mprint;

 

Then run your code again, and show us the log. (ALWAYS show us the log if you are getting errors) In particular, we need the log for the run of %ONE that has the errors, and we need to see the entire log for that run of %ONE (not just the errors).

 

Please use the </> icon to include your log in your reply.

PaigeMiller_0-1715196634946.png

--
Paige Miller
Lost_Gary
Quartz | Level 8

As i suspected, i was hitting the API to quickly. Apparently, some have a rate limit that my macro was exceeding.  I resolved my issue by slowing down my macro with the following code:

Data _null_;

call sleep(15,1);

run;

RichardAD
Quartz | Level 8

Use the headerout= option to save the servers response headers, and then you can log the information for examination and understanding on what to check for in terms of error handling.

filename hdrout temp ;
proc http ... headerout=hdrout ...
run ;
data _null_ ;
  infile hdrout ; input ; put _infile_ ;
run ;
filename hdrout ;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 375 views
  • 1 like
  • 3 in conversation