👆
こういうのを簡単に作る方法.DDEとかは使わない.SASのRWI(Report Writing Interface)とODS EXCELでやります
テストデータとして,
data wk1;
SUBJID="AAA";AETERM="事象1"; AESTDY=1;AEENDY=5;output;
SUBJID="AAA";AETERM="事象2"; AESTDY=3;AEENDY=8;output;
SUBJID="BBB";AETERM="事象1"; AESTDY=2;AEENDY=30;output;
SUBJID="BBB";AETERM="事象2"; AESTDY=-2;AEENDY=3;output;
SUBJID="BBB";AETERM="事象3"; AESTDY=4;AEENDY=.;output;
SUBJID="CCC";AETERM="事象1"; AESTDY=15;AEENDY=20;output;
run;
要は,開始と終了の相対日付(DY変数)をもっていればなんでもOK
終了日がnullの場合は,継続として最大までバーをひっぱる仕様を想定
以下 コードですが,面白いのがexcelに出力するSAS RWIの部分での指定が,信じられないぐらいシンプルなのと,セル幅が自動でlengthに連動してくれるので細かいメッシュにたいして何の範囲指定や命令を書かなくても全部えー感じにしてくれるところ.
この技術はわりと使える
proc sql noprint;
select min(min(AESTDY,1)) into:min trimmed from wk1;
select max(max(AESTDY,AEENDY)) into:max trimmed from wk1;
quit;
%put &=min;
%put &=max;
%let range =%eval( %sysfunc(range(&min,&max))+ (0<&min));
%put &=range;
data wk2;
set wk1;
array ar{&range.} $1.;
if &min < 1 then do;
st = AESTDY - &min + (AESTDY<1);
if ^missing(AEENDY) then en = AEENDY - &min + (AEENDY<1);
end;
else do;
st=AESTDY;
en=AEENDY;
end;
do i = 1 to ⦥
if st <=i <=en then ar{i}="Y";
else if st=i and missing(en) then ar{i}="Y";
else if st<=i and missing(en) then ar{i}="O";
end;
run;
%macro hed();
%do i = &min %to &max;
if &i ne 0 then ob.format_cell(data: "&i", style_attr: "background=blue color=white");
%end;
%mend;
%macro row();
%do i = 1 %to %eval(&range);
if ar&i="Y" then ob.format_cell(data: ar&i, style_attr: "background=red color=red");
else if ar&i="O" then ob.format_cell(data: ar&i, style_attr: "background=pink color=pink");
else ob.format_cell(data: ar&i, style_attr: "background=white color=white");
%end;
%mend;
ods excel options( sheet_name= "GANT" );
data _NULL_;
set wk2 end=EOF;
if _N_=1 then do;
dcl odsout ob();
ob.table_start();
*** header ;
ob.head_start();
ob.row_start();
ob.format_cell(data: "ID", style_attr: "background=darkblue color=white");
ob.format_cell(data: "Event", style_attr: "background=darkblue color=white");
ob.format_cell(data: "STDY", style_attr: "background=darkblue color=white");
ob.format_cell(data: "ENDY", style_attr: "background=darkblue color=white");
%hed();
ob.row_end();
ob.head_end();
end;
*** report ;
ob.row_start();
ob.format_cell(data: SUBJID);
ob.format_cell(data: AETERM);
ob.format_cell(data: AESTDY);
ob.format_cell(data: AEENDY);
%row();
ob.row_end();
if EOF then ob.table_end();
run;
ods excel close;