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""."
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!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: