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?
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""."
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""."
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!
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.