%macro xunhuan(ds=a,par=,delim=);
%let i=1;
%do %while(%scan(%quote(&par),&i,%quote(&delim)) ne );
proc sort data=&ds ;
by %scan(%quote(&par),&i,%quote(&delim));
run;
%let i=%eval(&i+1);
%end;
%mend;
%xunhuan(par=%str(year , qua , month , week , year qua ,id year, id year marks),delim=%str(,))
也可以是这样:
%let ds=a;
%let byvar=year , qua , month , week , year qua ,id year, id year marks;
data _null_;
n=count("&byvar",",")+1;
do i=1 to n;
code="proc sort data=&ds; "
||"by "||strip(scan("&byvar",i,","))||"; "
||"run;";
call execute(code);
end;
run;