w*****1 发帖数: 473 | 1 【 以下文字转载自 Statistics 讨论区 】
发信人: wz99331 (dotti), 信区: Statistics
标 题: a question about SAS
发信站: BBS 未名空间站 (Mon Apr 2 12:52:18 2012, 美东)
我需要用MACRO 语言,用DO LOOP 改变一个模版的5个固定参数创建一些新的DATA,检
测这些新的DATA最大似然值.下面是我的CODE, 但是不能运行,大家能否帮我看看?包子
酬谢!
data parents; set csgl.individs;
keep i QTP pedid dgeno;
if i <=2;
run;
/* Do loops for grid search */
/*Y=g+R(mixed model), where g=Major Gene(latent fixed effect)with 3
values: mudaa, mudab, mudbb and R = Residual(variance component)*/
/*the max, min, and std will be used as grid search ranges */
%macro loops;
proc means data=parents;
var QTP;
output out=range min=min max=max std=std mean=mean;
run;
proc print data=range;
run;
data temp; set range;
%do e=1 %to 10;
de=e*std/10;
%do q=1 %to 10;
dq=(q-1)*0.1;
%do i=1 %to 21;
mudaa=min+(i-1)*(max-min)/20;
%do j=1 %to 21;
mudab=min+(j-1)*(max-min)/20;
%do k=1 %to 21;
mudbb=min+(k-1)*(max-min)/20;
output;
data _NULL_;
set two;
call symput("mudaa", mudaa);
call symput("mudab", mubab);
call symput("mudbb", mudbb);
call symput("de", de);
call symput("dq", dq);
run;
%put mudaa=&mudaa mudab=&mudab mudbb=&mudbb de=&de dq=&dq;
%end;
%end;
%end;
%end;
%end;
run;
%mend;
%loops;
%macro new(mudaa=, mudab=, mudbb=, de=, dq=, indata=, outdata=);
data &outdata; set &indata;
lnl=log((((1-&dq)**2)*(1/sqrt(2*constant('PI')*&de))*exp(-0.5*(((QTP-mudaa)/
&de)**2))+
2*&dq*(1-&dq)*(1/sqrt(2*constant('PI')*&de))*exp(-0.5*(((QTP-mudaa)/&
de)**2))+
(&dq**2)*(1/sqrt(2*constant('PI')*&de))*exp(-0.5*(((QTP-mudaa)/&de)**2
))));
run;
proc means data=&outdata sum;
var lnl;
output out=lnnew sum=sum;
run;
%mend new;
%new(mudaa=-0.6, mudab=0.0, mudbb=0.8, de=0.1, dq=0.4,
indata=parents, outdata=Sgridsearch);
%new(mudaa=&mudaa, mudab=&mudab, mudbb=&mudbb, de=&de, dq=&dq,
indata=temp, outdata=gridsearch);
proc sort data=gridsearch;
by descending lnlikelihood;
output out=grid_sort_search;
data grid_search; set grid_sort_search;
if(_N_ =1);
proc print data=grid_search noobs; |
|