BookmarkSubscribeRSS Feed
94seanhogan
Fluorite | Level 6

I have a SAS program which imports these large JSON files which works 99.9% of the time but once a blue moon I get a JSON file which throws up the error message:

39 filename map2 temp;
40 libname json2 JSON map=map2 automap=reuse ;
NOTE: JSON data is only read once. To read the JSON again, reassign the JSON LIBNAME.
ERROR: Invalid JSON in input near line 15837 column 6649: Some code points did not transcode.
ERROR: Error in the LIBNAME statement.

Its not very realistic to open and interrogate the file as its to large. The best I could find was to change the encoding to be UFT-8, which SAS is already set to. 

 

My code is below.

Any suggestions as to how to investigate or solve the issue please do put them as I'm at a loss. 

Cheers

 

 

filename json "&jdir.\&Jfile.&uat..json" ;
filename json2 temp lrecl=250000; data _null_; infile json end=eof lrecl=250000; file json2 ; input ; if _n_=1 then put '[' @; else put ',' @; put _infile_; if eof then put ']'; run; filename map2 temp; libname json2 JSON map=map2 automap=reuse ;

 

 

2 REPLIES 2
Amir
PROC Star

Hi,

 

It looks like it is related to the below SAS note:

Usage Note 64615: The SAS® log displays the error "Invalid JSON in input near line XXX column XXX: Some code points did not transcode

https://support.sas.com/kb/64/615.html

 

 

Thanks & kind regards,

Amir.

Quentin
Super User

Checking that your SAS session is UTF-8 is a good step.  After that, I think you'll have to interrogate the file to identify the problematic characters.  Without knowing which characters are causing the problem, it will be difficult to solve.

 

Since your input file is apparently "JSONL" (i.e. JSON lines rather than a real JSON file) ,  that should make it easier to process the file in chunks, looking for the problematic line(s).  e.g.:

 

		data _null_;
		  infile json end=eof  lrecl=250000;
		  file json2 ;
		  input ;
		  if _n_=1 then put '[' @; else put ',' @;

		  if 1<=_n_<=1000 then put _infile_;  *check lines 1-1,000 of the JSON file;
if eof then put ']'; run;

 

The Boston Area SAS Users Group (BASUG) is hosting our in person SAS Blowout on Oct 18!
This full-day event in Cambridge, Mass features four presenters from SAS, presenting on a range of SAS 9 programming topics. Pre-registration by Oct 15 is required.
Full details and registration info at https://www.basug.org/events.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 896 views
  • 0 likes
  • 3 in conversation