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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 365 views
  • 1 like
  • 2 in conversation