SAS Excel一括変換するマクロ に書いたものを改良したものです。
最近は R ばかり使っていたので、作ったのを忘れていました (2007/07/02に作った物を多少弄ってあります)。
Macro Name: SAS to Excel (xls / csv) batch conversion macro Author: Triad Sou. Version: 1.1.1 License: GPL 3 or later Last Updated Date: 07/02/2007 Recommended Environment: Windows XP 32 bit, SAS 9.1.3
使い方
proc datasets lib = work kill; run; option linesize = 130 pagesize = 9999 mprint; dm 'log; clear; output; clear'; %let execpath = " "; %let Path = " "; %macro setexecpath; %let execpath = %sysfunc(getoption(sysin)); %if %length(&execpath) = 0 %then %let execpath = %sysget(sas_execfilepath); data _null_; do i = length("&execpath") to 1 by -1; if substr("&execpath", i, 1) = "\" then do; call symput("Path", substr("&execpath", 1, i)); stop; end; end; run; %mend setexecpath; %setexecpath; libname Out "&Path"; %include "&Path.conv1.1.1.sas"; data Out.sample1; do i = 1 to 10; r = rand('Normal'); output; end; run; /* default: output a combined xls file (*.xls only)*/ %MStart; /* output each datasets in each csv files */ %let ftype = csv; %MStart; /* output each datasets in each xls files */ %let ftype = xls; %let otype = 1; %MStart;
メモ
- データセットが無いディレクトリに対して実行したときに、エラーコードを返すように改良したい。
- ログ出力設定を戻す?かどうかを検討しておく。
- ファイル名指定出力は意味なさそうなので消しました、昔のを見て追加するのは簡単だと思います。