【发布时间】:2019-07-23 19:58:27
【问题描述】:
我有如下代码,我想在数据测试中创建一个 if 语句 [在新列中,我们称之为标志],我可以使用宏定义的五分位数 [来自宏中的 proc 单变量步骤 1]。最后我想看看每条记录是否在定义的分位数中,如果不是,标志应该是别的东西。
我在定义宏变量的步骤上停了下来。如何命令 SAS 将 Q1 定义为 proc 单变量输出的 pct10?
data test;
do x=1 to 100;
output;
end;
x=.;
output; output;
run;
example %quint(test,x,10 20 30 70)
%macro quint(input=,var=, pcts=);
/* calculate the cutpoints for the quintiles */
proc univariate data=&input;
var &var;
output out=quintile pctlpts=&pcts pctlpre=pct;
run;
/* write the quintiles to macro variables */
data _null_;
set quintile;
%do i=1 %to %sysfunc(countw(&pcts));
call symput(cats("Q",&i),cats("pct",%scan(&pcts,&i,' ')));
%put "&&Q&i";
%end;
run;
there should be data test with new column flag based on macrovariables created from proc univariate Q1 to Qx
%mend quint;
【问题讨论】: