I'm so happy to be able to update this post with the answer: a JSON libname engine is now in Base SAS 9.4 (maint 4).
Example:
filename resp temp;
/* Neat service from Open Notify project */
proc http
url="http://api.open-notify.org/astros.json"
method= "GET"
out=resp;
run;
/* Assign a JSON library to the HTTP response */
libname space JSON fileref=resp;
/* Print result, dropping automatic ordinal metadata */
title "Who is in space right now? (as of &sysdate)";
proc print data=space.people (drop=ordinal:);
run;
I never saw this reply until now (email SAS Communities email notifications don't work for me).
JSON *is* the format that the web application uses; it sends serialized data to my SAS Stored Process in JSON format, I have to parse it in SAS.
I guess there is no easy way, thanks.
There is no build in functionality to interpert a JSON data structure in SAS. The recommended option is to initiate an outside utility to conver the JSON object into a XML document. There are lots of options to do this. There are .NET applications, perl scripts, etc... Have the SAS Stored Process execute the necssary commands and export a more easily usable XML file. I know there are published documents around the web showing this type of process. I think maybe an entry in one of the SAS official Blogs. Take a look there for additional information.
Thanks for the suggestion.
XML isn't a handy option either, the webapp gives lots of different responses, I would have to create xmlmaps for each.
I was looking for something simpler, like a proc or macro that creates a SAS data set from a JSON string.
Is there an easy way to read JSON (JavaScript Object Notation) formatted data in SAS? Do we have any answer for this ?
I'm so happy to be able to update this post with the answer: a JSON libname engine is now in Base SAS 9.4 (maint 4).
Example:
filename resp temp;
/* Neat service from Open Notify project */
proc http
url="http://api.open-notify.org/astros.json"
method= "GET"
out=resp;
run;
/* Assign a JSON library to the HTTP response */
libname space JSON fileref=resp;
/* Print result, dropping automatic ordinal metadata */
title "Who is in space right now? (as of &sysdate)";
proc print data=space.people (drop=ordinal:);
run;
when i am running above program getting the below error:
ERROR: The JSON engine cannot be found.
ERROR: Error in the LIBNAME statement.
@arpitagarwal512 - the JSON engine was added in SAS 9.4 Maint 4. You can run:
proc product_status; run;
To see your version. It should return something like:
For Base SAS Software ... Custom version information: 9.4_M4 Image version information: 9.04.01M4P110916
In earlier versions of SAS, you would need to simply use DATA step or PROC DS2 to parse the JSON. It's not nearly as elegant as the JSON libname engine, but for simple JSON it works.
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.