2019年7月19日金曜日

「PROC REPORT」の「COMPUTE」がうまく動かないんだけど




以下の失敗例をご覧ください。

* 失敗例 ;
proc report data=sashelp.class;
    column name age;
    compute age;
        if age=13 then call define("age","style","style=[color=blue]");
    endcomp;
run;


「AGE=13だったらAGEの文字色を青にする」というのがやりたかったのに、青になってないじゃん、っていう失敗例です。




解説


さて、何がまずかったでしょうか。
まずは以下の前提知識が必要なのでお目通しを。。

REPORTプロシジャ入門4:集計【ANALYSIS】
REPORTプロシジャ入門10:数値変数の落とし穴



上のリンクの入門記事でも解説した通り、

REPORTプロシジャに指定した ”数値項目” は、以下のように「analysis sum」オプションが勝手について実行されます。

proc report data=sashelp.class;
    column name age;
    define name / display;
    define age / analysis sum;
run;



analysis項目ではなく普通の表示項目にしたい場合は、displayオプションを指定します。
以下の通り、display項目であればうまく書式設定できます。

proc report data=sashelp.class;
    column name age;
    define age / display;
    compute age;
        if age=13 then call define("age","style","style=[color=blue]");
    endcomp;
run;




もし意図的にanalysis項目のままにしたい場合、computeの中で以下のように「項目名.統計量」という書き方をする必要があります。

proc report data=sashelp.class;
    column name age;
    compute age;
        if age.sum=13 then call define("age.sum","style","style=[color=blue]");
    endcomp;
run;




0 件のコメント:

コメントを投稿