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;
SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!

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.

SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
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;
SAS Innovate 2025: Call for Content! Submit your proposals before Sept 16. Accepted presenters get amazing perks to attend the conference!
AJDELACRUZ0220
Fluorite | Level 6

this perfectly worked! thank you so much!

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