BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Hello,

 

I am trying to get a list of strings using proc json like below:


proc json out=json_in pretty;
export work.tweets /
nokeys nosastags;
run;

 

I get the result as list of lists

[

['a'],

['b'],

['c']

]

 

I want the result to be list of strings like that:

[ 'a',

'b',

'c']

 

the file tweets contains only one column called tweets containing strings a, b, c

 Is that possible using proc json?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Don't know about the PROC but it should be trivial in a DATA step.

data _null_;
  file json_in ;
  set tweets end=eof;
  if _n_=1 then put '[' @;
  else put '.' @;
  put tweets :$quote. ;
  if eof then put ']' ;
run;

Which will generate a nice pretty file like:

["a"
,"b"
,"c"
]

Instead of one with the commas in the wrong place.

 

If your values might include double quote characters you will need to confirm that the method the $QUOTE form uses to protect those characters is appropriate for a JSON file.  When the character used to quote a string appears in a string the normal way in SAS to indicate that is to double the embedded character.  So a string like He said, "Hello". will appear as

"He said, ""Hello""."

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

Don't know about the PROC but it should be trivial in a DATA step.

data _null_;
  file json_in ;
  set tweets end=eof;
  if _n_=1 then put '[' @;
  else put '.' @;
  put tweets :$quote. ;
  if eof then put ']' ;
run;

Which will generate a nice pretty file like:

["a"
,"b"
,"c"
]

Instead of one with the commas in the wrong place.

 

If your values might include double quote characters you will need to confirm that the method the $QUOTE form uses to protect those characters is appropriate for a JSON file.  When the character used to quote a string appears in a string the normal way in SAS to indicate that is to double the embedded character.  So a string like He said, "Hello". will appear as

"He said, ""Hello""."
ahmedmady94
SAS Employee
Thank you so much. That's so helpful.

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
  • 486 views
  • 1 like
  • 2 in conversation