I loved the sophistication yet the simplicity of Tom's solution. Here is one simple modification to Tom's original solution. JSON is Type sensitive, therefore if you needed to mimic SAS's original data types (Num -> JSON Num, Char -> JSON Char) here is what you need to use %macro json(in,out=_webout); data _null_; file &out ; if _n_=1 then _prefix='['; else _prefix=','; if _EOF then put ']'; set &in end=_EOF ; length _name $32 _value $300 _type $1; /* Added _type var def */ _sep = _prefix ||'{'; do until (upcase(_name)='_NAME'); call vnext(_name,_type); /* using _type to get the variable's data type */ if not (upcase(_name) in ('_PREFIX','_EOF','_NAME')) then do; _value = left(vvaluex(_name)); if (_type = 'C') then /* Quote Character values only */ put _sep $char2. _name :$quote. +(-1) ':' _value :$quote. ; else put _sep $char2. _name :$quote. +(-1) ':' _value ; _sep=' ,'; end; end; put ' }'; run; %mend json; %json(sashelp.class(obs=3),out=print); [{"Name":"Alfred" ,"Sex":"M" ,"Age":14 ,"Height":69 ,"Weight":112.5 } ,{"Name":"Alice" ,"Sex":"F" ,"Age":13 ,"Height":56.5 ,"Weight":84 } ,{"Name":"Barbara" ,"Sex":"F" ,"Age":13 ,"Height":65.3 ,"Weight":98 } ]
... View more