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
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;
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.
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?
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;
this perfectly worked! thank you so much!
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!
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.