楼主: 我女儿超靓
4565 15

SAS编程如何迭代求解,如何从A数据集中提取最后一行生成B数据集再重新代入到A中循环。 [推广有奖]

11
jingju11 发表于 2014-12-30 20:10:57
我女儿超靓 发表于 2014-12-28 14:04
data A;
input nit xit nic xic;
yi=log((xit/(nit-xit))/(xic/(nic-xic)));
两个问题:(1)第一次循环:按照每个数据记录依次计算得到第一个beta,作为下依次循环的初始值。知道最后收敛。(2)是否某些累加制在循环初始时应该归零。那个i=14是什么意思?
京剧

12
jingju11 发表于 2014-12-31 03:25:19
This code was based on my understanding on the method in your code. JingJu
  1. data B;
  2. beit0=0; beit=0; u0=0; jj=10;
  3. do while(jj>1e-8);
  4.   nLoops ++1; if nLoops >1e5 then leave;
  5.   call missing(s1, s1_, s2, m1, ss);
  6.   do pointx=1 to nobsx;
  7.     set A point=pointx nobs=nobsx;
  8.     xi    =1/(nit+nic);
  9.     wi1   =1/(si_square+beit0*xi);
  10.     wi2_x =wi1**2*xi;
  11.     wi2_x2=wi2_x*xi;
  12.     m1    ++(yi/si_square);
  13.     s1    ++(1/si_square);
  14.     s1_   ++(wi1);
  15.     s2    ++(wi2_x2);   
  16.     u     =m1/s1;
  17.     wiy_u =wi2_x*((yi-u)**2 +1/s1_ -si_square);
  18.     ss    ++(wiy_u);  
  19.   end;
  20.   beit    =ss/s2;
  21.   kk      =u-u0;
  22.   jj      =abs(beit-beit0);
  23.   output;  
  24.   beit0   =beit;
  25. end;
  26. stop;
  27. drop nit xit nic xic yi si_square xi;
  28. run;
复制代码

13
jingju11 发表于 2014-12-31 04:09:30
jingju11 发表于 2014-12-31 03:25
This code was based on my understanding on the method in your code. JingJu
I still doubt if I compute u and s1_ correctly. Are these values constant for fixed beta at each loop?
JingJu

14
jingju11 发表于 2014-12-31 05:10:23
jingju11 发表于 2014-12-31 04:09
I still doubt if I compute u and s1_ correctly. Are these values constant for fixed beta at each l ...
It makes more sense for me to iterate like that: JingJu
  1. data B2;
  2. nLoops=0; beit0=0; beit=0; jj=10; u0=0;
  3. array t[10,7] _temporary_;
  4. do pointx=1 to nobsx;/*values only depending on data*/
  5.     set A point=pointx nobs=nobsx;
  6.     array tt[6] nit xit nic xic yi si_square;
  7.     do i =1 to dim(tt);
  8.       t[pointx,i]=tt[i];
  9.     end;
  10.     t[pointx,7]=1/(t[pointx,1]+t[pointx,3]) ;
  11.     m1    ++(t[pointx,5]/t[pointx,6]);
  12.     s1    ++(1/t[pointx,6]);
  13. end;
  14. u     =m1/s1;
  15. do while(jj>1e-8);
  16.   nLoops ++1; if nLoops >1e5 then leave;
  17.   call missing(s1_, s2,  ss);
  18.   do i=1 to dim1(t);/*  get values of functions of beta*/
  19.     xi    =t[i,7];
  20.     wi1   =1/(t[i,6]+beit0*xi);
  21.     wi2_x =wi1**2*xi;
  22.     wi2_x2=wi2_x*xi;
  23.     s1_   ++(wi1);
  24.     s2    ++(wi2_x2);
  25.   end;
  26.   do i=1 to dim1(t);
  27.     xi    =t[i,7];
  28.     wi1   =1/(t[i,6]+beit0*xi);
  29.     wi2_x =wi1**2*xi;
  30.     wiy_u =wi2_x*((t[i,5]-u)**2 +1/s1_ -t[i,6]);
  31.     ss    ++(wiy_u);  
  32.   end;
  33.   beit    =ss/s2;
  34.   kk      =u-u0;/*  not sure what KK is for?*/
  35.   jj      =abs(beit-beit0);
  36.   output;  
  37.   beit0   =beit;
  38. end;
  39. stop;
  40. drop nit xit nic xic yi si_square xi i;
  41. run;
复制代码

15
sas9.4 发表于 2015-1-10 20:37:07
其实问题没那么复杂,你想办法把输入的数据格式处理一下,

16
jingju11 发表于 2015-1-17 09:57:05
sas9.4 发表于 2015-1-10 20:37
其实问题没那么复杂,你想办法把输入的数据格式处理一下,
What do you mean? JingJu

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-30 23:26