Hello,
I have the following table which is result of proc transpose:
I need a json structure like below:
{
"week": [1,2,3,.....53]
''year2012": [...entire column....]
"avg": [...entire column....]
"yhat": [...entire column....]
"sd": [...entire column....]
"ucl": [...entire column....]
"lcl": [...entire column....]
}
I have gotten the folloing code for creating my desire json structure:
data _null_;
file _webout;
set mydata end=_last;
array xcol{*} col:;
if _n_ = 1 then do;
put "{";
end;
put _name_ $quote. ":[" @;
do i = 1 to dim(xcol);
if i < dim(xcol) then do;
put xcol{i} "," @;
end;
else do;
put xcol{i} @;
end;
end;
if _last = 0 then do;
put "],";
end;
else do;
put "]";
end;
if _last = 1 then do;
put "}";
end;
run;
but when I ran above code I got the following result:
{
"week" :[],
"year2012":[],
"avg" :[],
"yhat" :[],
"sd" :[],
"ucl" :[],
"lcl" :[]
}
I am not sure why it does not have value?!!
I am new in SAS, I would really appriciated if someone help me.
Thanks,
Samira
Your havn't posted your log. Look for NOTEs or Warnings in it.
Assuming your variable names are: WEEK: , AVG: , YHAT: etc.
you should define arrays for each of them:
data _null_;
file _webout;
set mydata end=_last;
/* array xcol{*} col:; <<<<< are there variables with prefix COL ? ****/
array weekn{*} week:;
array yhatn{*} yhat:;
array agen{*} age:;
.... array per each variables prefix ...
.... your code, replacing the COL loop and dupliacte it per each array ...
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.