2

json ファイルを作成するこのマクロがありますが、
指定してもencoding='utf-8' bomutf-8 ファイルを取得できません。

%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;

jsonファイルを表示したWebページにアクセントが変な文字として表示されるので気付きました。
この問題は、json ファイルを崇高なテキストで開き、File>Save with Encoding>UTF-8 を実行するだけで解決されます。(BOM は必要ありません。)

utf-8 エンコーディングを強制する別の方法はありますか?

編集: Windows で SAS EG 7.1 、SAS 9.3 を使用しています。

4

1 に答える 1