BookmarkSubscribeRSS Feed
Taka_FUK_JPN
Fluorite | Level 6

お世話になっております.

 

proc sgplotで,月ごとの棒グラフ&折れ線グラフ(X軸:時期,Y軸:度数)を作成しているのですが,

X軸の表示方法についてご教示いただけないでしょうか.

 

現在,X軸のデータは,2017-01-01,2017-02-01,・・・に対応する

シリアル値をyymmd.で表示させているので2017-01,2017-02・・・の表示になっています.

このときに,"2017-"は,重複する情報なので,各年の最初の値のみ2017-01と表示させ,それ以降は,02,03,・・・と表示させたいのですが,

何か方法はございませんでしょうか(2017-01,・・・,2017-12,2018-01,02,・・・).

 

フォーマットを作成してみたのですが,フォーマットを適用すると

複数の年があるためか,2017年の2月と2018年の2月のデータがグラフ上重なってしまいます.

 

何か解決方法がございましたらご教示いただきたく存じます.

 

よろしくお願い申し上げます.

 

 

 

 

6 REPLIES 6
sasone
Quartz | Level 8

フォーマットを使用してしまうと、複数の情報が1つに集約されてしまいますので、
Annotateを使用する方法しか思い付きませんでした。

data stocks;
  set sashelp.stocks (where=(date >= "01jan2004"d
                                 and date <= "01dec2005"d
                                 and stock = "IBM"));
run;

data annotate;
  set stocks;
  label=put(date,yymmd.);
  if scan(label,2,"-")^="01" then label=scan(label,2,"-");
  function="text"; textsize=8;
  x1space="datavalue";
  y1space="graphpercent";
  x1=date; y1=22; anchor="left";
  width=100; rotate=-60;
  output;
  function="line"; linethickness=0.1;
  x2space="datavalue";
  y2space="graphpercent";
  x2=date;
  y1=23.5; y2=22.5;
  output;
run;

proc sgplot data=stocks sganno=annotate;
   title "Stock Volume vs. Close";
   vbar date / response=volume;
   vline date / response=close y2axis;
   xaxis display=(novalues noticks);
   yaxis offsetmin=0.15;
   y2axis offsetmin=0.15;
run;
title;
Taka_FUK_JPN
Fluorite | Level 6

sasone様

 

 

ありがとうございます.

ご教示頂いた方法で出来ました.

 

もう一点,annotationについてお伺いしたいのですが,

複数の異なるテキストをannotationで追加することは可能でしょうか.

年月の他に,タイトルのようなものを図中に挿入したいので・・・

 

annotationに使うデータを複数行にすれば,function="text"は何回も使用可能ですよね・・・?

sasone
Quartz | Level 8

1つのデータセットの中でfunction="text"を何度も使用することは可能ですが、
プログラムがややこしくなってしまいますので、別々のデータセットで作っておいて
後からつなぎ合わせた方が楽かも知れません。

data stocks;
  set sashelp.stocks (where=(date >= "01jan2004"d
                                 and date <= "01dec2005"d
                                 and stock = "IBM"));
run;
data anno1;
  set stocks;
  label=put(date,yymmd.);
  if scan(label,2,"-")^="01" then label=scan(label,2,"-");
  function="text"; textsize=8;
  x1space="datavalue";
  y1space="graphpercent";
  x1=date; y1=22; anchor="left";
  width=100; rotate=-60;
  output;
  function="line"; linethickness=0.1;
  x2space="datavalue";
  y2space="graphpercent";
  x2=date;
  y1=24.5; y2=23;
  output;
run;
data anno2;*タイトルのようなもの;
  function="text";
  textsize=9; textweight="bold";
  drawspace="graphpercent";
  x1=35; y1=15; label="2004年";
  output;
  x1=70; label="2005年";
  output;
run;
data annotate; set anno1 anno2; run;
proc sgplot data=stocks sganno=annotate;
   vbar date / response=volume;
   vline date / response=close y2axis;
   xaxis display=(novalues noticks);
   yaxis offsetmin=0.15;
   y2axis offsetmin=0.15;
run;
Taka_FUK_JPN
Fluorite | Level 6

sasone様

 

できました.

 

継ぎ足していけば良いので,わかりやすいです.

ありがとうございます.

 

 

amatsu
Obsidian | Level 7

 

以下、ちょっとご要望通りではないかもですが。。

 

proc sgplot data=sashelp.stocks (where=(date >= "01jan2004"d and date <= "01dec2005"d and stock="IBM"));;
   vbar date / response=volume;
   vline date / response=close y2axis;
   xaxis type=time interval=month;
   format date monyy7.;
run;

 

月が英語で表示されちゃいます、、

あと上の例だとグラフの幅が小さいために、目盛が一部表示されない(間引かれる)です。

 

 

なので、x軸の文字のサイズを小さくするとか、

 

   xaxis type=time interval=month valueattrs=(size=6pt);

 

 

最初にグラフ自体のサイズを大きくしちゃうとか、

   ods graphics / width=1000;

 

で目盛が間引かれるのを防げるかと思います。

 

 

 

Taka_FUK_JPN
Fluorite | Level 6

amatsu様

 

ご教示ありがとうございました.

 

英語表記ですが,シンプルで十分な方法です.

ありがとうございました.

 

ただ,SAS 9.3では,

"BARCHARTPARMステートメントは軸タイプに矛盾があります.プロットは作成されません."

のWARANINGが出てしまいました.

 

SAS Studioでは上手くいったので,SASのバージョンによるのかもしれません.

 

 

ありがとうございました.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Discussion stats
  • 6 replies
  • 2592 views
  • 3 likes
  • 3 in conversation