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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

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.

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
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;
It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
AJDELACRUZ0220
Fluorite | Level 6

this perfectly worked! thank you so much!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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