データセットをトレーニングセットと検証セットに分割するマクロを作成しました。次の%ifステートメントが正しく評価されておらず、最近マクロプロセッサdoes not make a distinction between character and numeric values as the rest of SAS does(SASドキュメントへのリンク)が原因であることが判明しました。以下に示すように、私は%のeval関数を使用してこれを確認した:それは、小数点として正しくマクロ変数「スプリット」のための私の入力を読み込みますように私はこの問題を解決するにはどうすればよいマクロは数値入力を文字に変換しています。それを数値に戻す方法は?
%else %if %eval(&split) <= 0 or %eval(&split) >= 1 %then %do;
%put ERROR: The specified split of the data must be within the following range of real numbers (0,1].;
%end;
?
次のサンプルコードを使用することができます。
data test (drop=i);
do i=1 to 1000;
a=round(uniform(1)*4,.01);
b=round(uniform(1)*10,.01);
c=round(uniform(1)*7.5,.01);
if b<2 then d=1;
else d=0;
if i<500 then y=1;
else y=0;
output;
end;
stop;
run;
%macro train_valid(split=);
%if &split = %then %put ERROR: Missing an input. Check to make sure the macro variable has an input.;
%else %if &split <= 0 or &split >= 1 %then %do;
%put ERROR: The specified split of the data must be within the following range of real numbers (0,1].;
%end;
%else %do;
proc surveyselect data=test samprate=&split seed=1000 out=Sample outall
method=srs noprint;
run;
data test_train;
set Sample;
where selected = 1;
run;
data test_valid;
set Sample;
where selected = 0;
run;
%end;
%mend;
%train_valid(split=.75);
これは、%evalまたは%sysevalf関数を正しく使用する方法を理解していなかったので、解決策がわかり、理解に役立ちました。ありがとうございました! – NicChik