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

Hi

 

I'm trying to convert json from a rest api to a dataset. In the JSON data there is an emoji, which SAS, or the proc json routine is unable to handle. I've played with idea of getting the data with python (don't know why), but not sure if python will handle this better.

 

Example code:

filename input   "testjson.json";
%let jsondata = '{"num_records": 1, "data": [[1, "texttexttext \ud83d\udc4d\ud83c\udffb"]], "data_type": "json"}';

libname posts json fileref=input;
proc datasets lib=posts ; quit;

The data array includes more attributes, but libname statement fails on the 4 encoded values at the end of the provided example and program throws the following error. The field is provided by users so there may be more...

ERROR: Invalid JSON in input near line 1 column 71: Some code points did not transcode.
ERROR: Error in the LIBNAME statement.

Is it possible to handle this in some way besides getting the developer to change their API (probably not feasible)?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

hi,

is the `jsondata` the content of the file?

I executed the following code on sas 9.4m6 (running with ENCODING=UTF8), to put the data into the text file:

filename input "testjson.json";

data _null_;
file input;
put '{"num_records": 1, "data": [[1, "texttexttext \ud83d\udc4d\ud83c\udffb texttext"]], "data_type": "json"}';
run;

libname posts json fileref=input;
proc datasets lib=posts ; quit;

proc print data = posts.alldata;
run;

proc print data = posts.data;
run;

proc print data = posts.root;
run;

and everything seems to be ok, log was clear and in the proc print I saw 👍 icon (thumbs up)

 

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Onyx | Level 15

hi,

is the `jsondata` the content of the file?

I executed the following code on sas 9.4m6 (running with ENCODING=UTF8), to put the data into the text file:

filename input "testjson.json";

data _null_;
file input;
put '{"num_records": 1, "data": [[1, "texttexttext \ud83d\udc4d\ud83c\udffb texttext"]], "data_type": "json"}';
run;

libname posts json fileref=input;
proc datasets lib=posts ; quit;

proc print data = posts.alldata;
run;

proc print data = posts.data;
run;

proc print data = posts.root;
run;

and everything seems to be ok, log was clear and in the proc print I saw 👍 icon (thumbs up)

 

All the best

Bart

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sindrew
Fluorite | Level 6

Hi bart

 

Thanks, 👍 to 👍. Yes jsondata is the content of the file (a bit unclear).

I'm on 9.4m5. Possible fix ther....but could encoding be an issue? I'm using wlatin1.

yabwon
Onyx | Level 15

My first approach would be to run UTF-8 sSAS session for utf-8 data.

 

Bart

 

 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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