w*****1 发帖数: 473 | 1 我需要用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; | g****8 发帖数: 2828 | | w*******n 发帖数: 469 | 3 all macro variables need to put percent sign prior to the variables. | B****k 发帖数: 188 | | w*****1 发帖数: 473 | 5 Thank you very much for your help!
我改了CODE如下: 现在已运行了1小时还没有停止,大家能否帮我看看? 谢谢!
data parents; set csgl.individs;
keep i QTP pedid dgeno;
if i <=2;
run;
option symbolgen mprint mlogic;
%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=lnlike sum=sumlike;
run;
proc print data=grid;
title "my grid";
run;
%mend;
%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=grid, outdata=gridsearch);
proc sort data=gridsearch;
by descending sumlike;
output out=grid_sort_search;
data grid_search; set grid_sort_search;
if(_N_ =1);
proc print data=grid_search noobs;
run;
data _NULL_;
set range;
call symput("min", min);
call symput("max", max);
call symput("std", std);
run;
data grid;
%do e=1 %to 10;
%do q=1 %to 10;
%do i=1 %to 21;
%do j=1 %to 21;
%do k=1 %to 21;
de=%sysevalf(&e*&std / 10);
dq=%sysevalf((&q-1)*0.1);
mudaa=%sysevalf(&min+(&i-1)*(&max - &min)/20);
mudab=%sysevalf(&min+(&j-1)*(&max - &min)/20);
mudbb=%sysevalf(&min+(&k-1)*(&max - &min)/20);
output;
%end;
%end;
%end;
%end;
%end;
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 */
proc means data=parents;
var QTP;
output out=range min=min max=max std=std mean=mean;
run;
proc print data=range;
run; | g****8 发帖数: 2828 | 6 %new(mudaa=&mudaa, mudab=&mudab, mudbb=&mudbb, de=&de, dq=&dq,
indata=grid, outdata=gridsearch);
这些variable都没有在macro外面定义,你怎么用呀? | g****8 发帖数: 2828 | 7 前面那个macro还写得好点,大概就是macro variable引用的不对。
后面这个错了很多,楼主你是不是贴错code了。 |
|