BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
CR-Horton
Fluorite | Level 6

Hi All,

I am using Proc JSON to output a SAS dataset into JSON format. The first block of JSON below is the default output and the second block is what I am trying to do.

Basic Proc JSON code:
proc json out="path\name.json" pretty nosastags;
export dataset;
run;

Default JSON output: [ { "category_id": 123, "name": "name_example", "description": "description_example", "page_title": "page_example", "meta_description": "meta_example", "URL": "url_example" } ] What I need: [ { "category_id": 123, "name": "name_example", "description": "description_example", "page_title": "page_example", "meta_description": "meta_example", "URL": { "path": "url_example" } } ]

I have tried various statements within Proc JSON (write values, arrays, objects, etc.) but that doesn't seem to get me what I need. What do I need to do to achieve the output I shared above?

Thanks in advance for your help!

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why not just write it yourself?  JSON files are just text.

data _null_;
  file "path\name.json" ;
  set have end=eof;
  if _n_=1 then put '[' / ' {' @;
  else put ',{' @;
  put 
    '"category_id":' category_id
  /' ,"name":' name :$quote.
  /' ,"description":' description :$quote.
  /' ,"page_title":' page_title :$quote.
  /' ,"meta_description":' meta_description :$quote.
  /' ,"URL":{"path":' url :$quote. '}'
  /' }'
  ;
  if eof then put ']';
run;

 

Results

[
 {"category_id":123
 ,"name":"name_example"
 ,"description":"description_example"
 ,"page_title":"page_example"
 ,"meta_description":"meta_example"
 ,"URL":{"path":"url_example" }
 }
]

PS Why place continuation characters at the end of the lines where they are hard for humans to scan?

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Why not just write it yourself?  JSON files are just text.

data _null_;
  file "path\name.json" ;
  set have end=eof;
  if _n_=1 then put '[' / ' {' @;
  else put ',{' @;
  put 
    '"category_id":' category_id
  /' ,"name":' name :$quote.
  /' ,"description":' description :$quote.
  /' ,"page_title":' page_title :$quote.
  /' ,"meta_description":' meta_description :$quote.
  /' ,"URL":{"path":' url :$quote. '}'
  /' }'
  ;
  if eof then put ']';
run;

 

Results

[
 {"category_id":123
 ,"name":"name_example"
 ,"description":"description_example"
 ,"page_title":"page_example"
 ,"meta_description":"meta_example"
 ,"URL":{"path":"url_example" }
 }
]

PS Why place continuation characters at the end of the lines where they are hard for humans to scan?

CR-Horton
Fluorite | Level 6
Awesome! Thanks a lot, Tom. Appreciate the quick help.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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