I have this macro that creates a json file,
but even though I have specified encoding='utf-8' bom
I don't get an utf-8 file.
%macro json4datatables_useformat(ds,path,file,charvars,numvars)
/
DES="json4datatables(ds,path,file,charvars,numvars)";
/* creates a json with no headers
* a bit like a csv without the first line
* it takes thus less space
* but you have to know which column is what
*/
data _null_;
length line $300;
set &ds nobs=nobs end=end;
file "&path.&file." encoding='utf-8' bom/**/ ;
line = '[';
%if &charvars ne %then %do;
%do i=1 %to %sysfunc(countw(&charvars));
%let charvar = %scan(&charvars, &i);
%if &i ne 1 %then %do;
line = cats(line,',');
%end;
line = cats(line,'"',vvalue(&charvar),'"');
%end;
%end;
%if &numvars ne %then %do;
%do i=1 %to %sysfunc(countw(&numvars));
%let numvar = %scan(&numvars, &i);
line = catx(',',line,vvalue(&numvar));
%end;
%end;
line = cats(line,']');
if _n_=1 then put '{"data": [';
if not end then put line +(-1) ',';
else do;
put line;
put ']}';
end;
run;
%mend json4datatables_useformat;
I noticed because accents appear as strange charactes on the web page where I display the json file.
And the issue is solved simply by opening the json file in sublime text and doing File>Save with Encoding>UTF-8.
(with BOM isn't necessary.)
Is there another way to force utf-8 encoding?
EDIT: I'm using SAS EG 7.1 , SAS 9.3 on windows.