批量拟合并提取结果参数的SAS程序

filename f_list pipe "dir D:\three\dat /b";
data mylist;
infile f_list;
input file :\$14.;
run;
data mylist;
set mylist;
where file ? ‘fit’;
call symput(‘n’,_n_);
put file _n_;
run;
%macro getn;
data _null_;
set mylist;
%do i=1 %to &n.;
if _n_=&i. then call symput("fn&i.",file);
%end;
%mend;
%getn;
%macro inverse;

%do i=1 %to &n.;
data ex;
infile "D:\three\dat\%CMPRES(&&fn&i.)" firstobs=2 ;
input x y;
run;

ods listing close;
ods output ParameterEstimates = paras ;
proc nlin data=ex ;
parms a1=100  a2=100 a3=100  ta1=10 ta2=10 ta3=10   e=10;
model y=a1*exp(-x/ta1)+a2*exp(-x/ta2)+a3*exp(-x/ta3)+e;
run;
ods listing;

data inver (keep= name parameter estimate);
set paras;
name=scan("&&fn&i.",1);
run;

proc append base=inversx data=inver ;
run;
%end;
%mend;
%inverse
proc sort data=inversx;
by  name;
run;
proc transpose data=inversx out=final (drop=_name_);
var  estimate ;
id parameter;
by name;
run;

data ex (drop=aa1-aa3 xa1-xa3 i j);
set final;
aa1=ta1;aa2=ta2;aa3=ta3;
xa1=a1;xa2=a2;xa3=a3;
call sortn(of ta:);
array arr_a{3} a1-a3;
array arr_aa{3} aa:;
array arr_xa{3} xa:;
do i=1 to 3;
do j= 1 to 3;
if arr_aa{j}=ordinal(i,of ta:) then arr_a{i}=arr_xa{j};
end;
end;
run;
proc print data=ex;
run;