%macro test(dsin=, byvar=,pctlow=, pcthigh=, dsout=);
proc sort data=&dsin;
by &byvar;
run;
proc univariate noprint data=&dsin;
var var;
output out=quintile pctlpts=&pctlow &pcthigh pctlpre=pct;
by &byvar;
run;
data &dsout(drop=pct&pctlow pct&pcthigh);
merge test(in=a) quintile(in=b);
by &byvar;
if pct&pctlow<=var<=pct&pcthigh;
run;
%mend;
%test(dsin=test, byvar=year qua, pctlow=0, pcthigh=10, dsout=want);