|
|
データセットの存在チェック
[OS]ALL
[リリース]
[キーワード] Base SAS, EXIST DATA SET
[質問]
SCLのEXIST関数のように、目的のデータセットが存在しない場合、処理を回避したり代替のデータを指定するような処理を、SASプログラムで記述できますか。
[回答]現在割り当てられているライブラリ参照名とデータセット名を持っているSASデータビュー (SASHELP.VMEMBER.VIEW)を検索して、目的のデータセットを検査できます。 マクロプログラムを使用して、存在チェックを行うプログラムの例を以下に示します。
/* マクロプログラムの定義 */
%global exist;
%macro existchk(lib=WORK,data=);
%do;
options nonotes noreplace;
data _null_;
retain exist "0";
set sashelp.vmember(where=
(memtype='DATA' and libname="&lib"))
end=end;
if memname="&data" then exist="1";
if end then call symput("exist",exist);
run;
options notes replace;
%if &exist=1 %then %do;
/* 存在する場合の処理 */
%put note: %upcase(&lib..&data)
が存在します.;
%end;
%else %do;
/* 存在しない場合の処理 */
%put warning: %upcase(&lib..&data)
はありません.;
%end;
%end;
%mend existchk;
/* マクロプログラムの使用例 */
/* (例)sasuser.class の存在チェック */
%existchk(lib=SASUSER,data=CLASS);
|
|||||