1
我剛剛開始在SAS並遇到一些麻煩。我想從兩個數據集中獲取觀察值的數量,並將這些值分配給現有的全局宏變量。然後我想找到兩者中較小的一個。這是我迄今爲止的嘗試:SAS MIN功能中缺少操作員在哪裏?
%GLOBAL nBlue = 0;
%GLOBAL nRed = 0;
%MACRO GetArmySizes(redData=, blueData=);
/* Takes in 2 Army Datasets, and outputs their respective sizes to nBlue and nRed */
data _Null_;
set &blueData nobs=j;
if _N_ =2 then stop;
No_of_obs=j;
call symput("nBlue",j);
run;
data _Null_;
set &redData nobs=j;
if _N_ =2 then stop;
No_of_obs=j;
call symput("nRed",j);
run;
%put &nBlue;
%put &nRed;
%MEND;
%put &nBlue; /* outputs 70 here */
%put &nRed; /* outputs 100 here */
%put %EVAL(min(1,5));
%GetArmySizes(redData=redTeam1, blueData=blueTeam); /* outputs 70\n100 here */
%put &nBlue; /* outputs 70 here */
%put &nRed; /* outputs 100 here */
%MACRO PrepareOneVOneArmies(redData=,numRed=,blueData=,numBlue=);
/* Takes in two army data sets and their sizes, and outputs two new army
data sets with the same number of observations */
%let smallArmy = %eval(min(&numRed,&numBlue));
%put &smallArmy;
%local numOneVOne;
%let numOneVOne = %eval(&smallArmy-%Eval(&nBlue - &nRed));
%put &numOneVOne;
data redOneVOne; set &redData (obs=&numOneVOne);
run;
data blueOneVOne; set &blueData (obs=&numOneVOne);
run;
%MEND;
%PrepareOneVOneArmies(redData=redTeam1,numRed=&nRed,blueData=blueTeam,numBlue=&nBlue);
/* stops executing when program gets to %let smallArmy =... */
redTeam1是一個有100個觀測值的數據集,blueTeam有70個觀測值。
我現在運行到哪裏,每當我調用函數「最小」我得到的問題:
"ERROR: Required operator not found in expression: min(1,5)"
或
"ERROR: Required operator not found in expression: min(100,70)"
我缺少什麼?
「閔」似乎是一個足夠簡單的功能。另外,如果它很重要,我正在使用SAS的大學版。
啊!非常感謝!這工作完美。並感謝您對代碼效率低下的建議。 –