FORMAT SAS

【SAS】FORMATプロシージャはフォーマットルールを定義し、値を書き換える

投稿日:2021年12月1日 更新日:

今回はFORMATプロシージャについて解説します。


/* format */
data data1;
  番号="111111"; test = 10;
    output;
  番号="222222"; test = 20;
    output;
  番号="333333"; test = 30;
    output;
  番号="444444"; test = 40;
    output;
  番号="555555"; test = 50;
    output;
  番号="666666"; test = 60;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
  51 - 100 = 'High';
run;


proc print data = data1;
  format test point.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。

/* test1 */
data data1;
  番号="111111"; test1 = 10;
    output;
  番号="222222"; test1 = 20;
    output;
  番号="333333"; test1 = 30;
    output;
  番号="444444"; test1 = 40;
    output;
  番号="555555"; test1 = 50;
    output;
  番号="666666"; test1 = 60;
    output;
run;


proc format;
  value point 1  -   50   = 'Low'
              51 -   100  = 'High';
run;


proc print data = data1;
  format test point.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • data1にtestという変数は無いため、WARNINGとなる。

/* 110 */
data data1;
  番号="111111"; test = 10;
    output;
  番号="222222"; test = 20;
    output;
  番号="333333"; test = 30;
    output;
  番号="444444"; test = 40;
    output;
  番号="555555"; test = 60;
    output;
  番号="666666"; test = 110;
    output;
run;


proc format;
  value point 1  -   50   = 'Low'
              51 -   100  = 'High';
run;


proc print data = data1;
  format test point.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 「point」のルールにない値はそのまま表示される。

/* High2 */
data data1;
  番号="111111"; test = 10;
    output;
  番号="222222"; test = 20;
    output;
  番号="333333"; test = 30;
    output;
  番号="444444"; test = 40;
    output;
  番号="555555"; test = 60;
    output;
  番号="666666"; test = 110;
    output;
run;


proc format;
  value point 1  -   50   = 'Low'
              51 -   100  = 'High'
              110-   200  = 'High2';
run;


proc print data = data1;
  format test point.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’、110 – 200 = ‘High2’とする「point」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 「point」のルールが3つ以上でもいける。

/* point point2 */
data data1;
  番号="111111"; test = 10;  test1 = 10;
    output;
  番号="222222"; test = 20;  test1 = 20;
    output;
  番号="333333"; test = 30;  test1 = 30;
    output;
  番号="444444"; test = 40;  test1 = 40;
    output;
  番号="555555"; test = 50;  test1 = 50;
    output;
  番号="666666"; test = 60;  test1 = 60;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
              51 - 100  = 'High'
       point2 1  -   50 = 'Low1'
              51 - 100  = 'High1';
run;


proc print data = data1;
  format test point.;
  format test1 point2.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • formatプロシージャにより1 – 50 = ‘Low1’、51 – 100 = ‘High1’とする「point2」というルールを設定したい。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 変数test1をpoint2.のフォーマットルールで書き換えたい。
  • 複数のフォーマットルールは1文で書けない。

/* point point2(2) */
data data1;
  番号="111111"; test = 10;  test1 = 101;
    output;
  番号="222222"; test = 20;  test1 = 200;
    output;
  番号="333333"; test = 30;  test1 = 300;
    output;
  番号="444444"; test = 40;  test1 = 400;
    output;
  番号="555555"; test = 50;  test1 = 500;
    output;
  番号="666666"; test = 60;  test1 = 600;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
              51 - 100  = 'High'
       point2 101  -150 = 'Low1'
              151 - 200 = 'High1';
run;


proc print data = data1;
  format test point.;
  format test1 point2.;
run; 


  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • formatプロシージャにより101 – 150 = ‘Low1’、151 – 200 = ‘High1’とする「point2」というルールを設定したい。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 変数test1をpoint2.のフォーマットルールで書き換えたい。
  • 複数のフォーマットルールは1文で書けない。(全て範囲が異なっていても)

/* point; point2(3); */
data data1;
  番号="111111"; test = 10;  test1 = 101;
    output;
  番号="222222"; test = 20;  test1 = 200;
    output;
  番号="333333"; test = 30;  test1 = 300;
    output;
  番号="444444"; test = 40;  test1 = 400;
    output;
  番号="555555"; test = 50;  test1 = 500;
    output;
  番号="666666"; test = 60;  test1 = 600;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
              51 - 100  = 'High';
  value point2 101  -150 = 'Low1'
              151 - 200 = 'High1';
run;


proc print data = data1;
  format test point.;
  format test1 point2.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • formatプロシージャにより101 – 150 = ‘Low1’、151 – 200 = ‘High1’とする「point2」というルールを設定したい。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 変数test1をpoint2.のフォーマットルールで書き換えたい。
  • フォーマットルール名は最後に数字が使えない。

/* point pointt */
data data1;
  番号="111111"; test = 10;  test1 = 101;
    output;
  番号="222222"; test = 20;  test1 = 200;
    output;
  番号="333333"; test = 30;  test1 = 300;
    output;
  番号="444444"; test = 40;  test1 = 400;
    output;
  番号="555555"; test = 50;  test1 = 500;
    output;
  番号="666666"; test = 60;  test1 = 600;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
              51 - 100  = 'High';
  value pointt 101  -150 = 'Low1'
              151 - 200 = 'High1';
run;


proc print data = data1;
  format test point.;
  format test1 pointt.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • formatプロシージャにより101 – 150 = ‘Low1’、151 – 200 = ‘High1’とする「pointt」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 変数test1をpointt.のフォーマットルールで書き換える。
  • フォーマットルールを別の文に分け、最後が数字でなければ、正しく実行できる。

/* point pointt(2) */
data data1;
  番号="111111"; test = 10;  test1 = 10;
    output;
  番号="222222"; test = 20;  test1 = 20;
    output;
  番号="333333"; test = 30;  test1 = 30;
    output;
  番号="444444"; test = 40;  test1 = 40;
    output;
  番号="555555"; test = 50;  test1 = 50;
    output;
  番号="666666"; test = 60;  test1 = 60;
    output;
run;


proc format;
  value point 1  -   50 = 'Low'
              51 - 100  = 'High';
  value pointt 1  -   50= 'Low1'
              51 - 100  = 'High1';
run;


proc print data = data1;
  format test point.;
  format test1 pointt.;
run; 

  • formatプロシージャにより1 – 50 = ‘Low’、51 – 100 = ‘High’とする「point」というルールを設定する。
  • formatプロシージャにより1 – 50 = ‘Low1’、51 – 100 = ‘High1’とする「pointt」というルールを設定する。
  • 変数testをpoint.のフォーマットルールで書き換える。
  • 変数test1をpointt.のフォーマットルールで書き換える。
  • フォーマットルールを別の文に分け、最後が数字でなければ、正しく実行できる。
  • 範囲が被っていても正しく実行できる。

-FORMAT, SAS

執筆者:


comment

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

関連記事

【SAS】^=(ノットイコール)

今回は^=について解説します。 /* ^=”” */ data data1; id=”A”; chiku=”SHINJUKU”; output; id=”B”; chiku=”ICHIGAYA”; o …

【SAS】データセットのエンコードを答えさせる問題【CONTENTS】【SAS Base Programming対策7】

今回はデータセットのエンコードを答えさせる問題について解説します。SAS Base Programming試験を受けたときに出題されました。 data data1; Id1=1111; Id2=111 …

【SAS】OUTPUTとDELETEの「明示的な使い方」「暗黙的な使い方」

今回はOUTPUTとDELETEにスポットを当てていきたいと思います。 /* output, delete無し */ data data1; Id1=1111; Char1=”AAAA”; outpu …

【SAS】プロパティ表示を使う方法

今回はプロパティ表示について触れていきます。 /* data1_1 */ data data1; id1=”1111″; id2=”1111″; id3=”1111″; output; id1=”22 …

【SAS】SASで良く使うテクニック。その3 「Ctrl+D」~データセットのオブザベーション数が多いとき~【Excel】

今回はSASで良く使うテクニックということで、データセットのオブザベーション数(行数)が多いときは「Ctrl+D」が役に立つ理由を解説していきます。 (参考:【SAS】SASで良く使うテクニック。その …