SAS MIN 函数中缺少的运算符在哪里?
Where is the missing operator in the SAS MIN function?
我刚开始使用 SAS,运行 遇到了一些麻烦。我想从两个数据集中获取观察值的数量,并将这些值分配给现有的全局宏变量。然后我想找到两者中较小的一个。这是我目前的尝试:
%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 个观察值。
我现在 运行 遇到这个问题,每当我调用函数 "Min" 我得到:
"ERROR: Required operator not found in expression: min(1,5)"
或
"ERROR: Required operator not found in expression: min(100,70)"
我错过了什么?
"Min" 似乎是一个足够简单的函数。另外,如果重要的话,我使用的是 SAS 的大学版。
在宏语言中使用函数时,您需要将函数包装在 %SYSFUNC()
中。这有助于 sas 区分可能是 min 的词与对实际函数的引用。
%put %sysfunc(min(1,5));
与您的问题无关,但是对于获取数据集的大小,读取完整数据集是一种低效的方法。考虑改用字典 table (SASHELP.VTABLE)。
我刚开始使用 SAS,运行 遇到了一些麻烦。我想从两个数据集中获取观察值的数量,并将这些值分配给现有的全局宏变量。然后我想找到两者中较小的一个。这是我目前的尝试:
%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 个观察值。
我现在 运行 遇到这个问题,每当我调用函数 "Min" 我得到:
"ERROR: Required operator not found in expression: min(1,5)"
或
"ERROR: Required operator not found in expression: min(100,70)"
我错过了什么?
"Min" 似乎是一个足够简单的函数。另外,如果重要的话,我使用的是 SAS 的大学版。
在宏语言中使用函数时,您需要将函数包装在 %SYSFUNC()
中。这有助于 sas 区分可能是 min 的词与对实际函数的引用。
%put %sysfunc(min(1,5));
与您的问题无关,但是对于获取数据集的大小,读取完整数据集是一种低效的方法。考虑改用字典 table (SASHELP.VTABLE)。