全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1190 0
2012-04-29
One of the useful tip in IML programming is to vectorize operation in IML.  It is ineifficient to do the matrix operation in element level ( loop through the index). As shoed in the following example that vectorizing operation beates element operation about 5 times in cpu time.

177  %let n=500000;
178
179  proc iml;
NOTE: IML Ready
180
181    call randseed(20);
182    x=j(&n,1,.);
183    e=j(%eval(&n+1),1,.);
184    e1=x;
185    call randgen(x, 'uniform');
186    call randgen(e, 'normal');
187    idx=2:%eval(&n+1);
188    idx2=1:&n;
189    e0=e(|idx|);
190    e=e(|idx2|);
191    y=1+2*x+0.7*e+e0;
192    *print e e0 x y;
193    quit;
NOTE: Exiting IML.
NOTE: 6 workspace compresses.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.13 seconds
      cpu time            0.12 seconds


194
195
196  proc iml;
NOTE: IML Ready
197
198    call randseed(20);
199    x=j(&n,1,.);
200    y=j(&n,1,.);
201    e=j(%eval(&n+1),1,.);
202    e1=x;
203    call randgen(x, 'uniform');
204    call randgen(e, 'normal');
205    do i=1 to &n;
206      y=1+2*x+0.7*e+e[i+1];
207    end;
208    *print e  x y;
209    quit;
NOTE: Exiting IML.
NOTE: 187 workspace compresses.
NOTE: PROCEDURE IML used (Total process time):
      real time           0.56 seconds
      cpu time            0.56 seconds
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

分享

扫码加好友,拉您进群