BookmarkSubscribeRSS Feed
adilar39
Obsidian | Level 7

Hello everyone, I would like to ask some questions.

 

I usually use SAS Studio to call data from API. That API made by my colleague has a 10 thousand maximum data to reduce chance of connection loss because of the big number. But sometimes, the data inside is more than 10 thousand, so they made paging for every 10 thousand data. The API would look like this:

https://site.com/admin/api/v1/survey?ID=111111&type=long&page=1

 

When I don't use the page parameter, it would works just fine. But when I use the page parameter when the data is over 10 thousand, this error show up.

SyntaxError: Unexpected end of JSON inputSyntaxError: Unexpected end of JSON input

 The code that I used to call the data:

 

FILENAME request HTTP
'https://site.com/admin/api/v1/survey?surveyID=111111&type=long&page=1'
user='user@user.com' password='user123' debug;
DATA NULL;
INFILE request;
INPUT;
PUT INFILE;
RUN;
libname test1 JSON fileref=request;

data work.data_testing;
	set test1.root;
run;

 

 

At first, I thought the error would be in the API links. But when I check one by one for every page, it open just fine.

Is there any solution for this? Or is this error caused by API side?

Thanks.

 

 

 

4 REPLIES 4
SASJedi
SAS Super FREQ

Because this works OK without the page parameter, I'd suspect the API. Perhaps it isn't properly terminating the JSON object for each page when paginating the results. 

Check out my Jedi SAS Tricks for SAS Users
adilar39
Obsidian | Level 7
I've tried some trial and error and found out that when I call only 2 pages with 20 thousand rows data, it works. But when I add another page, that error would show up.
SASJedi
SAS Super FREQ

This error almost always indicates malformed JSON or a response that is NOT JSON at all (like a 404 HTML response page). So I have questions:

1. When does the error you specified occur?

2. Is the error generated by SAS? If so, is it from the PROC HTTP step, the LIBNAME statement, or the DATA step?

3. Have you looked at the raw JSON file to see if you can identify the problem?

 

Check out my Jedi SAS Tricks for SAS Users
LinusH
Tourmaline | Level 20

Maybe not helping with the current issue, but if you have issues with data transfer size, timeouts etc, you may should look into other solutions such as file transfer, queuing/messaging (e.g. Kafka).

Data never sleeps

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
  • 4 replies
  • 926 views
  • 2 likes
  • 3 in conversation