*DDE;
*宣言部;

/******************
●1_1. dde_init
・SASシステムオプション設定
・DDEシステム定義
・各種日付変数作成
《必須グローバル変数》
path3:帳票保存先のフォルダ
file_nm:ファイル名
《使い方》
%dde_init;
********************/
%macro dde_init;
/*options noxwait noxsync mprint mlogic symbolgen;*/
options noxwait noxsync;
/* %global today today_out today_eu_out today_eu2_out today_eu3_out time_out hhmm_out zhhmmss_out shhmm_out;*/

data _null_;
    call symputx("today",put(today(),yymmddn8.));*ex 20190508;
    call symputx("today_out",put(today(),yymmdd10.));*ex.2019/05/08;
    call symputx("today_eu_out",put(today(),ddmmyy10.));
    call symputx("today_eu2_out",put(today(),yymmddn8.));
    call symputx("today_eu3_out",put(today(),yymmddn8.));
    call symputx("time_out",put(time(),time.));*ex 9:34:35;
    call symputx("hhmm_out",compress(put(time(),hhmm.),":");*ex. 935;
    call symputx("zhhmmss_out",compress(put(time(),tod.),":");*ex. 093435;
    call symputx("zhhmm_out",compress(put(time(),tod5.),":");*3x. 0934;
run;
%mend dde_init;
/**************
●1_2. sht_prm・・・シート特有のパラメータ設定
・データセット(&ds)のオブザベーション数を取得
・データセット(&ds)を作成
・グローバル変数作成データセットオブザベーション数:nobs、データ終了業:row_max、データ開始行:row_start_data
《必須グローバル変数≫
ds:データセット名、row_title:タイトル行、row_header:データヘッダー行、col_max:出力する項目数
《使い方》
%let ds=z_200;
%let row_title=3;
%let row_header=1;
%let col_max=8;
%sht_prm;
*********************/
%macro sht_prm;
    %global nobs row_max row_start_data;
    %let nobs=0;*データ数初期化;
    data &ds._outds;
        set &ds. end=eof;
        if eof then do;
            call symputx("nobs",_n_);
        end;
        row_num=1;
    run;
    /* 0obs対応 */
    %if &nobs.=0 %then %do;
        %let obs=1;
    %end;
    %else %do;
        %let obs=&nobs.;
    %end;
    /* データ範囲を特定(固定の総件数/列数の設定 演算) */
    *初期化;
    %let row_max=0;
    %let row_start_data=0;
    data _null_;
        call symputx("row_max",sum(&row_title.,&row_header.,&obs.));
        call symputx("row_start_data",sum(&row_title.,&row_header.,1));
    run;
    data _null_;
        file exxc_sys;
        put '[workbook.activate("'"&sht_nm."'")]';
    run;
%mend;

/**************
●2_1. dde_open・・・Excelを開く
《必須グローバル変数≫
path4 :ひな形のフォルダ
file_nm:ファイル名
《使い方》
%dde_open(full_name=%str(&path4\temp_file__nm..xlsx));
*********************/
%macro dde_open(full_name=);
    x "start excel";
    filename exc_sys dde 'excel|system';
    data_null_;
        rc=sleep(5);
    run;;
    /*  読み取り専で開く */
    data _null_;
        file exc_sys;
        put '[error(false)]';
        put '[open("'"&full_name."'",,true)]';
    run;
    /*     待機 */
    data _null_;
        rc=sleep(5);
    run;
    
%mend dde_open;
/**************
●2_2. file_save・・・Excelの保存
《必須グローバル変数≫
path :保存先のフォルダ
file_nm:ファイル名
《使い方》
%file_save(full=%str(&path4\file__nm..xlsx));
*********************/
%macro file_save(file=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[error(false)]';
        put '[open("'"&full."'")]';
    run;
%mend file_save;
/**************
●2_3. file_close・・・Excelを閉じる
《引数》quit 1:ウィンドウを閉じる 1以外:ウィンドウを閉じない
《使い方》
%file_close(quit=1);
*********************/
%macro file_close(quit=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[close(false)]';
        %if &quit.=1 %then %do;
            put '[quit()]';
        %end;
    run;
%mend file_close;
/**************
●3_1. r1c1_general・・・r1c1形式の設定
《引数》type 1:a1形式 2:r1c1形式
《使い方》%r1c1_general(type=2);
*********************/
%macro r1c1_general(type=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put "[options.general(&type.)]";
    run;
%mend r1c1_general;
/**************
●3_2. sht_activate・・・シートをアクティブにする
《引数》sht_nm :アクティブにするシート名
《使い方》%sht_activate(sht_nm=シート名);
*********************/
%macro sht_activate(sht_nm=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[workbook.activate("'"&sht_nm."'")]';
    run;
%mend sht_activate;
/**************
●3_3. sht_copy・・・シートをコピーする
《必須グローバル変数》
path4 :ひな形のフォルダ
temp_file_nm:ワークブック名(ひな形のブック名)
《引数》
sht_nm :コピー元シート名
wb_name_ext:ワークブック名(拡張子を含む)
obj_id:コピーされたシートの何番目に配置させるか
《使い方》%sht_copy(sht_nm=シート名,wb_name_ext=&temp_file_nm..xlsx,obj_id=2);
*********************/
%macro sht_copy(sht_nm=,wb_name_ext=,obj_id=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[workbook.activate("'"&sht_nm."'")]';
    run;
%mend sht_copy;
/**************
●3_4. sht_name_change・・・シートを変更する
《必須グローバル変数》
sht_nm_pre :ひな形のシート名(変更前)
sht_nm:作成帳票のシート名(変更後)
《使い方》
%let sht_nm_pre=sheet1;
%let sht_nm=帳票1;
%sht_name_change;
*********************/
%macro sht_name_change(sht_nm=,wb_name_ext=,obj_id=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[workbook.name("'"&sht_nm_pre."'","'"&sht_nm"'")]';
    run;
%mend sht_name_change;
/**************
●3_5. sht_delete・・・シートの削除
《引数》
sht_nm:ファイル名
《使い方》
%sht_delete(sht_nm=sht1(2));
*********************/
%macro sht_delete(sht_nm=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[error(false)]';
        put '[workbook.delete("'"&sht_nm."'")]';
    run;
    /*     待機 */
    data _null_;
        rc=sleep(5);
    run;
%mend sht_delete;
/**************
●3_6. sht_insert・・・シートの挿入
《引数》
obj_id:
1  worksheet
2 chart
3 excel 4 macro sheet
4 excel 4 international macro sheet
5(reserved)
6 microsoft excel visual basic module
7 dialog
《使い方》
%sht_insert(obj_id=1);
*********************/
%macro sht_insert(obj_id=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put "[workbook.insert(&obj_id.)]";
    run;
%mend sht_insert;
/**************
●3_7. sht_next_active・・・右隣のシートをアクティブにする
《使い方》
% sht_next_active;
*********************/
%macro sht_next_active;
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[workbook.next()]';
    run;
%mend sht_next_active;
/**************
●3_8. freeze_panes・・・ウィンドウ枠の固定;
《引数》col_split :列番号、row_split:行番号
《使い方》
% freeze_panes(col_split=,row_split=);
*********************/
%macro freeze_panes(col_split=3,row_split=&row_start_data.);
    filename exc_sys dde 'excel|system';    
    /*data _null_;
        file exc_sys;
        put '[freeze.panes(false)]';
    run;
*/
data _null_;
        file exc_sys;
        put '[workbook.activate("'"&sht_nm."'")]';
        %if "&col_split."="" and "&row_split."^="" %then %do;
            put '[select("'"r&row_split.r&col_split."'")]';
            put "[freeze.panes(true,&col_split.,&row_split.)]";
            put "[freeze.panes(true,0,&row_split.)]";
        %end;
        %if "&row_split."="" and "&col_split."^="" %then %do;
            put '[select("'"r&row_split.r&col_split."'")]';
            put "[freeze.panes(true,&col_split.,0)]";
        %end;
        %if "&row_split."^="" and "&row_split."^="" %then %do;
            put '[select("'"r&row_split.r&col_split."'")]';
            put "[freeze.panes(true,&col_split.]";
        %end;        
    run;
    run;
%mend freeze_panes;
/**************
●3_9. set_filter・・・フィルタを設定する
《引数》range :セルのアドレス 例:r5c3
《使い方》%set_filter(range=r&row_start_data.c1);
*********************/
%macro set_filter(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put '[filter()]';
    run;
%mend set_filter;
/**************
●3_10. set_print_area・・・印刷範囲を設定する
《引数》range :セルのアドレス 例:r5c3:r100c10
《使い方》%set_print_area(range=r1c1:r%eval(&row_max.+1)c&col_max);
*********************/
%macro set_print_area(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[set.print_area("'"&range."'")]';
    run;
%mend set_print_area;
/**************
●3_11. set_page_break・・・改ページを設定する
《引数》range :セルのアドレス 例:r5c3:r100c10
《使い方》%set_print_area(range=r1c1:r%eval(&row_max.+1)c&col_max);
*********************/
%macro set_page_break(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[set.page.break]";
    run;
%mend set_page_break;
/**************
●3_10. set_print_area・・・印刷範囲を設定する
《引数》range :セルのアドレス 例:r5c3:r100c10
《使い方》%set_print_area(range=r1c1:r%eval(&row_max.+1)c&col_max);
*********************/
%macro set_print_area(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[set.print_area("'"&range."'")]';
    run;
%mend set_print_area;
/**************
●4_1. range_select・・・セル範囲を選択する
《引数》range :セルのアドレス 例:r5c3:r100c10
《使い方》%range_select(range=r1c1:r%eval(&row_max.+1)c&col_max);
*********************/
%macro range_select(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
    run;
%mend range_select;
/**************
●5_1. cell_format・・・セル範囲を選択する
《引数》range :セルのアドレス 例:r5c3:r100c10
《使い方》%cell_format(range=r1c1:r%eval(&row_max.+1)c&col_max,format_type=&str(#,##0));
*********************/
%macro cell_format(range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put '[format.numger("'"&format_type."'")]';
    run;
%mend cell_format;
/**************
●5_2. format_name・・・セル範囲のフォント名を設定をする
《引数》range :セルのアドレス 例:r5c3
format_name:MSゴシック、araial
《使い方》%range_select(range=r1c1:r%eval(&row_max.+1)c&col_max,f_name=MSゴシック);
*********************/
%macro format_name(range=,f_name=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put '[format.font("'"&f_name"'")]';
    run;
%mend format_name;
/**************
●5_3. format_bold・・・セル範囲のフォントスタイルを設定をする
font.properties(font,font_stype,size,strikethrough,superscript,subscript,outline,shadou,underline,color,normal,backgound,start_char,ch)
《引数》range :セルのアドレス 例:r5c3
yn:1 bold
《使い方》%format_bold(range=r&row_start_data.c1,yn=1);
*******************/
%macro format_bold(range=,yn=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[format.font(,,&yn.)]";
    run;
%mend format_bold;
/**************
●5_4. font_size・・・セル範囲のフォントサイズを設定をする
《引数》range :セルのアドレス 例:r5c3
font_size:10、12
《使い方》%font_size(range=r5c3,font_size=10);
*******************/
%macro font_size(range=,font_size=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[format.font(,&font_size.)]";
    run;
%mend font_size;
/**************
●5_5. cell_clear・・・セル範囲のデータを消す
《引数》range :セルのアドレス 例:r5c3
clear_type:1:書式とデータ、2:書式のみ、3:データのみ
《使い方》%font_size(range=r5c3,clear_type=1);
*******************/
%macro cell_clear(range=,clear_type=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[format.font(,&font_size.)]";
    run;
%mend cell_clear;
/**************
●5_6. cell_insert・・・選択位置にセルの挿入
《引数》range :セルのアドレス 例:r5c3
insert_type:
1:shifts cells left
2:shifts cells up
3:deletes entire row
4:deletes entire column
《使い方》%cell_insert(range=r5c3,insert_type=1);
*******************/
%macro cell_insert(range=,insert_type=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[insert(,&insert_type.)]";
    run;
%mend cell_insert;
/**************
●5_7. cell_delete・・・選択位置からセルを削除
《引数》range :セルのアドレス 例:r5c3
delete_type:
1:shifts cells left
2:shifts cells up
3:deletes entire row
4:deletes entire column
《使い方》%cell_delete(range=r5c3,delete_type=1);
*******************/
%macro cell_delete(range=,insert_type=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        put "[edit.delete(,&delete_type.)]";
    run;
%mend cell_delete;
/**************
●6_1. sht_output_data・・・データ部を出力(0オブザベーション対応)
《必須グローバル変数》
temp_file_nm :ひな形のブック名
sht_nm:作成帳票のシート名
var:出力項目
ds:出力対象のデータセット
《%sht_prm実行で作成》
nobs:&dsのオブザベーション数
《引数》
range:出力先のセルのアドレス
word:0オブザベーションの時に出力する文言
《使い方》
%sht_output_data(range=r&row_start_data.c1:r&row_max.,word=%str(該当する情報なし));
*********************/
%macro sht_output_data(range=,word=);
    filename exc dde "excel|[&temp_file_nm..xlsx]&sht_nm.!&range.";
    %if &noobs.>0 &then %do;
        data _null_;
            set &ds_outds;
            file exc dlm="09"x dsd lrecl=50000 notab;
            put &var.;
        run;
    %else %do;
        data _null_;
            set &ds_outds;
            file exc dlm="09"x dsd lrecl=50000 notab;
            put &word.;
        run;
    %end;
%mend sht_output_data;

/**************
●6_2. sht_output・・・データセットを出力(0オブザベーション対応なし)*タイトル部など;
《必須グローバル変数》
temp_file_nm :ひな形のブック名
sht_nm:作成帳票のシート名
row_title:シートのタイトル行数
《%sht_prm実行で作成》
row_max:データ終了行
《引数》
ds:出力対象のデータセット
var_name:出力項目
range:出力先のセルのアドレス
《使い方》
%sht_output(ds=title,var_name=out_t,range=r1c1:r&row_title.c1);
%sht_output(ds=footer,var_name=out_t,range=r%eval(&row_max.+2)c1);
*********************/
%macro sht_output(ds=,var_name=,range=);
    filename exc dde "excel|[&temp_file_nm..xlsx]&sht_nm.!&range.";
    data _null_;
        set &ds;
        file exc dlm="09"x dsd lrecl=50000 notab;
        put &var_name.;
    run;
%mend sht_output;
/**************
●6_3. sht_input・・・エクセルデータをデータセットに取込
《必須グローバル変数》
temp_file_nm :ひな形のブック名
sht_nm:作成帳票のシート名
row_title:シートのタイトル行数
《%sht_prm実行で作成》
row_max:データ終了行
《引数》
ds:出力対象のデータセット
var_name:出力項目
range:入力元のセルのアドレス
《使い方》
%sht_input(ds=testdt,var_name=col1-col10,length 100,range=r1c1:r65536c10);
*********************/
%macro sht_input(range=,word=);
    filename exc dde "excel|[&temp_file_nm..xlsx]&sht_nm.!&range.";
    data _null_;
        set &ds;
        infile exc dlm="09"x dsd lrecl=50000 notab;
        input &var_nm.;
    run;
%mend sht_output_data;
/**************
●7_1. set_vhline_inside・・・内側罫線を引く;
《必須グローバル変数》
col_max:出力する項目数
《%sht_prm実行で作成》
row_max:データ終了行
row_start_data:データ開始行
《引数》
input_type 線種 0:線なし、1:中線、2:太線、7:点線
line_side 線側 1:外枠、2:左、3:右、4:上、5:下、6:網掛け、7:外枠色、左色、上色、下色
row_start 開始行 例4、&row_start_data、%eval(&row_max.+1)
row_end 終了行 例) 28、&row_max、%eval(&row_max.+1)
mod_column 選択列 例) 1、%str(1,2,3)、%str()および空白の時、前列を対象とする
《使い方》
%set_vhline_inside(line_type=1,line_side=3,row_start_data=&row_start_data,row_end=&row_max,mod_column=%str(1,2,3,4,5,6,7));
*********************/
%macro set_vhline_inside(line_type=,line_side=,row_start_data=,row_end=,mod_column=);
    data _null_;
        length word $20.;
        word="";
        do i=1 to &line_side.-1;
            word=cats(word,",");
        end;
        putlog word;
        call symputx("word2",cats(word,&line_type));
    run;
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        %do i=1 %to &col_max;
            put '[select("'"&r&row_start.c&i.:r&row_end.c&i"'")]';
            %if "&mod_colnum."^="" %then %do;
                if &i. in (&mod_column.) then do;
                    put "[border(&word2.)]";
                end;
            %end;
        %end;
    run;
%mend set_vhline_inside;

/**************
●7_2. set_vhline_outside・・・外側罫線を引く;
《必須グローバル変数》
col_max:出力する項目数
《%sht_prm実行で作成》
row_max:データ終了行
row_start_data:データ開始行
《引数》
input_type 線種 0:線なし、1:中線、2:太線、7:点線
line_side 線側 1:外枠、2:左、3:右、4:上、5:下、6:網掛け、7:外枠色、左色、上色、下色
range 列番号の指定:セル範囲を指定
《使い方》
%set_vhline_outside(line_type=1,range=&row_start_data.c1:r&row_max.c&col_max.);
*********************/
%macro set_vhline_outside(line_type=,range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';        
        put "[border(&line_type.)]";
    run;
%mend set_vhline_inside;
/**************
●7_3. cond_vhline_inside・・・内側罫線を引く(条件付き縦横罫線);
《必須グローバル変数》
row_title:タイトル行数
row_header:項目行数
ds:出力対象データセット
《引数》
input_type 線種 0:線なし、1:中線、2:太線、7:点線
line_side 線側 1:外枠、2:左、3:右、4:上、5:下、6:網掛け、7:外枠色、左色、上色、下色
col_start 開始列 例4、&row_start_data、%eval(&row_max.+1)
col_end 終了列 例) 28、&row_max、%eval(&row_max.+1)
cond 条件式 例)id^=""
《使い方》
%cond_vhline_inside(line_type=1,line_side=4,col_start=1,col_end=3,cond=id^="");
*********************/
%macro cond_vhline_inside(line_type=,line_side=,col_start=,col_end=,cond=id^="");
    data _null_;
        length word $20.;
        word="";
        do i=1 to &line_side.-1;
            word=cats(word,",");
        end;
        putlog word;
        call symputx("word2",cats(word,&line_type));
    run;
    %let statement=;
    %let times=%sysfunc(ceil(&nobs./100));
    %do i=1 %to ×
    proc sql noprint;
        select
        cats("put'[select(""r",sum(&row_title.,&row_header.,row_num)
        ,"c&col_start.:r",sum(&row_title.,&row_header.,row_num),"c&col_end.",""")]';"
        ,"put '[border(&word2.)]';")
        into
        :statement separeted by " "
        from &ds_outds f0
            where &cond.
            and f0.row_num>(&i.-1)*100
            and f0.row_num<=(&i.)*100
            ;
        quit;
        *%put %str("&statement.");*test;
        filename exc_sys dde 'excel|system';
        data _null_;
            file exc_sys;
            &statement.;
        run;
    %end;
%mend cond_vhline_inside;
/**************
●8_1. set_text_location・・・文字位置
《%sht_prm実行で作成》
row_max:データ終了行
row_start_data:データ開始行
《引数》
align_h_type :文字位置《横位置》1:標準、2:左詰、3:中央、4:右詰、5:繰り返し、6:両端揃え、7:選択範囲で中央、8:均等
align_v_type :文字位置《縦位置》1:上詰、2:中央、3:下詰、4:両端揃え、5:均等
mod_column :選択列 例)%str(1,2,3)、%str()および空白の時、前列を対象とする
row_start:開始行
row_end: 終了行
《使い方》%set_text_location(align_h_type=4,align_v_type=2,mod_column=%str(2,3,4),
row_start=&row_start_data.,row_end=&row_max);
*********************/
%macro set_text_location(align_h_type=,align_v_type=,mod_column=,row_start=,row_end=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        %do i=1 %to &col_max.;
            put '[select("'"r&row_start.c&i.:r&row_end.c&i."'")]';
            %if "&mod_colnum."^="" %then %do;
                if &i. in (&mod_colnum.) then do;
                    put "[alignment(&align_h_type.,false,&align_v_type.)]";
                end;
            %end;
            %else %do;
                    put "[alignment(&align_h_type.,false,&align_v_type.)]";
            %end;
        %end;
    run;
%mend set_text_location;
/**************
●8_2. set_text_wrap・・・文字の折り返し
《%sht_prm実行で作成》
row_max:データ終了行
row_start_data:データ開始行
《引数》
align_type :《全文字表示》1:折り返し表示、0または省略:折り返し表示を行わない
mod_column :選択列 例)%str(1,2,3)、%str()および空白の時、前列を対象とする
row_start:開始行
row_end: 終了行
《使い方》%set_text_wrap(align_type=1,mod_column=%str(2,3,4),
row_start=&row_start_data.,row_end=&row_max);
*********************/
%macro set_text_wrap(align_type=,mod_column=,row_start=,row_end=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        %do i=1 %to &col_max.;
            put '[select("'"r&row_start.c&i.:r&row_end.c&i."'")]';
            %if "&mod_colnum."^="" %then %do;
                if &i. in (&mod_colnum.) then do;
                    put "[alignment(,&align_type.)]";
                end;
            %end;
            %else %do;
                put "[alignment(,&align_type.)]";
            %end;
        %end;
    run;
%mend set_text_wrap;
/**************
●9_1. set_auto_fit・・・列幅・行幅調整(自動)
《引数》
object_type : 1:列、2:行
size : (空白):オートフィット、任意の数値(ポイント):例)20
row_end: 終了行
range:列番号の指定:セル範囲を指定;例)r6c12:r10c12、r&row_start_data.cq:r&row_max.c&colmax.
《使い方》
自動:%set_auto_fit(object_type=1,size=,range=r&row_start_data.cq:r&row_max.c&colmax.);*オートフィット;
固定:%set_auto_fit(object_type=1,size=20,range=r&row_start_data.cq:r&row_max.c&colmax.);*20ポイントで設定;
*********************/
%macro set_auto_fit(object_type=,size=,range=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        if &object_type.=1 then do;
            if "&size"^="" then 
                put "[column.width(&size.)]";
            else
                put "[column.width(,,true,3)]";
            end;
        end;
        if &object_type.=2 then do;
            if "&size"^="" then 
                put "[column.height(&size.)]";
            else
                put "[column.height(,,true,3)]";
            end;
        end;
    run;
%mend set_auto_fit;
/**************
●9_2. cell_hidden・・・列幅・行幅調整(自動)
《引数》
range:列番号の指定:セル範囲を指定;例)r6:r10、c5:c5
display: 1:非表示、2:再表示
《使い方》
%cell_hidden(range=r6:r10,display=1);*非表示;
*********************/
%macro cell_hidden(range=r6:r10,display=1);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put "[column.width(,'&range',true,&display.)]";
    run;
%mend cell_hidden;
/**************
●9_3. cell_merge・・・セルの結合/分割
《引数》
range:列番号の指定:セル範囲を指定;例)r6c1:r10c2
merge: 0:結合を外す、1:結合する
《使い方》
%cell_merge(range=r6c1:r10c2,merge=1);*結合する;
*********************/
%macro cell_merge(range=,merge=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[error(false)]';
        put '[select("'"&range."'")]';        
        put "[slignment(,,,,,,,&merge.)]";
    run;
%mend cell_merge;
/**************
●9_4. set_auto_fit_remote・・・変則列幅調整
特定した項目の最大文字数をもとに、別のカラムの列幅を設定する。
《必須グローバル変数》
ds:出力対象のデータセット
《引数》
pos_length_var:最大文字数調査項目
range:列範囲を指定(1列のみ指定可);例)r2c2:r10c2、r&row_start_data.c2:r&row_max.c2
《使い方》
set_auto_fit_remote(pos_length_var=%str(soc_nm,pt_nm),range=r&row_start_data.c2:r&row_max.c2);*オートフィット;
*********************/
%macro set_auto_fit_remote(pos_length_var=,range=);
    %let cnt=%sysfunc(count(&pos_length_var,%str(,)));
    data _null_;
        do i=1 to &cnt.+1;
            call symput(cats("var",i),scan("&pos_length_var",i,",","M"));
        end;
    run;
    data wk_ds;
        set 
        %do var=1 %to %eval(&cnt+1);
            &ds(rename=&&varYvar=wkcol1)
        %end;
        keep wkcol1;
    run;
    data _null_;
        set wk_ds;
        retain wk_text;
        if wk_text<length(wkcol1) then wk_text=length(wkcol1);
        call symputx("word_size",wk_text);
    run;
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[select("'"&range."'")]';
        if "&word_size."^="" then 
            put "[column.width(&word_size.)]";
        else
            put "[column.width(,,true,3)]";
    run;
%mend set_auto_fit_remote;
/**************
●9_2. cell_hidden・・・列幅・行幅調整(自動)
《引数》
range:列番号の指定:セル範囲を指定;例)r6:r10、c5:c5
display: 1:非表示、2:再表示
《使い方》
%cell_hidden(range=r6:r10,display=1);*非表示;
*********************/
%macro cell_hidden(range=r6:r10,display=1);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put "[column.width(,'&range',true,&display.)]";
    run;
%mend cell_hidden;
/**************
●9_3. cell_merge・・・セルの結合/分割
《引数》
range:列番号の指定:セル範囲を指定;例)r6c1:r10c2
merge: 0:結合を外す、1:結合する
《使い方》
%cell_merge(range=r6c1:r10c2,merge=1);*結合する;
*********************/
%macro cell_merge(range=,merge=);
    filename exc_sys dde 'excel|system';
    data _null_;
        file exc_sys;
        put '[error(false)]';
        put '[select("'"&range."'")]';        
        put "[alignment(,,,,,,,&merge.)]";
    run;
%mend cell_merge;