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 is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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