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

Hello,

 

Why Am I having this error on my JSON libname:

 

ERROR: Invalid JSON in input near line 1 column 1: Encountered an illegal character.

ERROR: Error in the LIBNAME statement.

 

I used the following code:

 

proc json out='C:\Users\GARCIAAV\Dropbox\JSON\test.json' pretty;

export sashelp.class (where=(age=12));

run;

filename help temp;

/* Neat service from Open Notify project */

proc http

/* url="http://api.open-notify.org/astros.json"*/

url="https://www.dropbox.com/home/JSON?preview=test.json"

method= "GET"

out=help;

run;

/* Assign a JSON library to the HTTP response */

libname test JSON fileref=help;

 

Thanks,

 

Ave

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

If you have the JSON file locally, you simply assign a SAS fileref with the FILENAME statement to that location.  No need to jump through the PROC HTTP hoops.  That's only for retrieving JSON data from a web service.  

 

Here's an example.  Adjust the file paths for your system.

 

/* Create a JSON file */
proc json out="c:\temp\test.json" pretty;
 export sashelp.class (where=(age=12));
run;

/* Reference the JSON file and read it in using JSON libname */
filename testjs "c:\temp\test.json";
libname test JSON fileref=testjs;

proc datasets lib=test;
quit;

proc print data=test.sastabledata_class;
run;
Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!

View solution in original post

4 REPLIES 4
ChrisHemedinger
Community Manager

If I understand your test correctly, you're testing a "round trip" of PROC JSON to the JSON libname.  By reading the result from Dropbox, you'll need to provide a URL to the "raw" view of the Dropbox file.  The link you're using goes to a web page that presents a preview of the file, but does not serve up the file itself.

 

See my blog post about using SAS to read from Dropbox.  You'll have to get the "direct file" link from your Dropbox view.

Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
AJDELACRUZ0220
Fluorite | Level 6

Thank you for your reply and I apologize for if I am not clear.

 

What I really want to do is to import JSON file to SAS using JSON libname. If I have my JSON file in my local directory, what will be the syntax that I need to used?

ChrisHemedinger
Community Manager

If you have the JSON file locally, you simply assign a SAS fileref with the FILENAME statement to that location.  No need to jump through the PROC HTTP hoops.  That's only for retrieving JSON data from a web service.  

 

Here's an example.  Adjust the file paths for your system.

 

/* Create a JSON file */
proc json out="c:\temp\test.json" pretty;
 export sashelp.class (where=(age=12));
run;

/* Reference the JSON file and read it in using JSON libname */
filename testjs "c:\temp\test.json";
libname test JSON fileref=testjs;

proc datasets lib=test;
quit;

proc print data=test.sastabledata_class;
run;
Become an Explorer! Join SAS Analytics Explorers to learn and complete challenges that earn rewards!
AJDELACRUZ0220
Fluorite | Level 6

this perfectly worked! thank you so much!

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

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