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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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