dxystata 发表于 2014-10-16 20:50 
如果数据集aaa是这样,如何保持数据集中ccc中name取值的顺序为aaa数据中name的顺序c a b
如果每个site里的name取值的顺序都相同的话:
data ccc;
set aaa end=last;
by site name notsorted;
if _n_=1 then call execute("data ddd(keep=name site: drop=site); merge ");
if first.site then call execute(cats("ccc(where=(site=",site,") rename=(_x1=site",site,"))"));
if last then call execute("; by name_order; run;");
if first.site then name_order=0;
if first.name then do; _x1=catx(" ",x1); name_order+1; end;
else if not first.name then _x1=catx(" ",_x1,x1);
if last.name;
retain _x1 ;
run;
proc sql noprint;
select distinct cats("site",site,"=",quote(strip(x))) into : label separated by " " from bbb;
quit;
proc datasets;
modify ddd;
label &label;
run;
quit;