BookmarkSubscribeRSS Feed
ellen09
Fluorite | Level 6

Hi,

 

I retrieve a JSON file which looks like below, and I am trying to parse it. The value of name "C" is quoted as a string, however, it is also an array. I am trying to parse it with both libname json engine and DS2 procedure, but I don't know how to parse inside the value of "C".  Any help appreciated!

 

{
"result": {
"status": "good"
},
"reviews": [
{
"A": 32,
"B": "name1",
"C": "{\"x1\": {\n \"A1\": {\"y1\": [\n {\n \"fname\": \"p1\",\n \"mname\": \"p2\",\n }\n ]\n}}",
"D": "New"
},
{
"A": 38,
"B": "name2",
"C": "{\"x1\": {\n \"B1\": {\"y1\": [\n {\n \"fname\": \"q1\",\n \"mname\": \"q2\",\n }\n ]\n}}",
"D": "New"
}
]
}

4 REPLIES 4
ellen09
Fluorite | Level 6

I am hoping to get a data set like this:

Capture.PNG

 

 

ChrisNZ
Tourmaline | Level 20

The simplest if the JSON's structure is quite constant:

FNAME=scan(C, 9,':\"{}');

MNAME=scan(C,12,':\"{}');

 

If the string varies more, you may have to look for the positions of fname and mname.

 

If it varies a lot, you may have to resort to regular expressions to isolate the bits you want, or use several statements.

 

A data step allows you to read the JSON string using an input statement, but DS2 cannot afaik:

https://communities.sas.com/t5/SAS-Data-Management/Parsing-a-string-variable/td-p/157459

 

 

 

ellen09
Fluorite | Level 6
That helps. Thank you

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
  • 914 views
  • 0 likes
  • 2 in conversation