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-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 717 views
  • 1 like
  • 2 in conversation