BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
xLoreleix
Calcite | Level 5

Hello,

I am trying to call an API that only accepts one argument at a time. I want to call it about 100 times. I have my code set up so that the returned data is saved into a txt file "resp". Currently, every time I call the API, the "resp" file is replaced. I would rather each call's returned data be appended to the file.

Here is my code so far: (I will add in an array of ids eventually)

%MACRO callapi (id=);
proc http
url ="api/url/etc"
method="get"
out=resp;
run;
%MEND callapi;
%callapi(id=id1);

 

I guess one solution would be to create a new folder and have every response create a new file and append them afterwards, but I'd rather not do that if I don't have to.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

I assume that you're going to take that txt file and convert it to SAS data, correct? So in your macro, add a DATA step that reads the file and creates a data set with a new name (work.data_01, work.data_02, etc.). You can then later append the data sets together when you're all done.

 

I use this technique all of the time. Alternatively, you could use the FILENAME statement to remap resp to a new file before each call, maybe placing into a file like "data_01.txt", "data_02.txt", etc. Then finish with a DATA step that uses INFILE with a wildcard notation to read all of the data at once.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

View solution in original post

1 REPLY 1
ChrisHemedinger
Community Manager

I assume that you're going to take that txt file and convert it to SAS data, correct? So in your macro, add a DATA step that reads the file and creates a data set with a new name (work.data_01, work.data_02, etc.). You can then later append the data sets together when you're all done.

 

I use this technique all of the time. Alternatively, you could use the FILENAME statement to remap resp to a new file before each call, maybe placing into a file like "data_01.txt", "data_02.txt", etc. Then finish with a DATA step that uses INFILE with a wildcard notation to read all of the data at once.

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!

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
  • 1 reply
  • 353 views
  • 1 like
  • 2 in conversation