<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[SAS IML交互式数据处理及小实例]]></title><description><![CDATA[<pre><code>/*3 交互式矩阵语言 IML*/
/*3.1  概述*/
Proc IML;
	Sc=15.25;
	Vh={1 2};
	Print Sc;
	Print Vh;
Quit;
</code></pre>
<pre><code>/*3.2  数据集操作语句*/
Proc IML;
filename out 'user.matrix'; 
file out; 
    do i=1 to nrow(x); 
       do j=1 to ncol(x); 
          put (x[i,j]) 1.0 +2 @; 
       end; 
     	put;
	end; 
   closefile out;
QUIT;
</code></pre>
<pre><code>/*3.3  循环语句*/
/*3.4  分支语句*/
/*3.5  CALL语句*/
/*3.5  实例*/

/*实例1：方程组求解*/

PROC IML;
		A={2 3 1, 4 -1 2, 3 -1 1};
		b={10, 13,8};
		X=INV(A)*b;
		PRINT A b X;
QUIT;
</code></pre>
<pre><code>/*	实例2：非线性方程的迭代求解*/
PROC IML;
  	maxiter=50; /* 定义最大迭代次数 */ 
    converge=.000001; /* 定义收敛精度*/ 
       /* 定义待求解函数 */ 
start fun; 
      f= x**3-x+2; 
   finish fun; 
       /* 定义导函数 */ 
   start deriv; 
      df=3*x**2-1; 
   finish deriv; 
start newton; 
      run fun;          
      do iter=1 to maxiter  /* 迭代直到最大迭代次数 */ 
      while(max(abs(f))&gt;converge);            /* 收敛则提前退出 */ 
         run deriv;                /* 计算导函数 */ 
         delta=f/df;      /* 计算增量 */ 
         x=x-delta;                    /* 更新值 */ 
         run fun;                      /* 计算函数值 */ 
     end; 
   finish newton; 
do; 
      print "Solving the equation:" ,; 
      x=-1;     /* 赋初值 */ 
      run newton; 
	  iter=iter-1;
	  print x f iter; 
	  if iter&gt;maxiter then print 'Not converge!';
   end;
QUIT;
</code></pre>
<pre><code>/*实例3:把环比指数转化为定基指数*/
data a;
input id index;
cards;
1 100
1 93
1 103
1 97
2 100
2 97
2 116
2 98
run;
proc iml;
use a;
read all into mat;
index=j(8,1,1);
index[1]=mat[1,2];
do i=2 to 8 by 1;
   if (mat[i,1]=mat[i-1,1]) then index[i]=index[i-1]*mat[i,2];
   else index[i]=mat[i,2]; 
end;
 print index;
create b from index;
append from index;
close b;
run;
</code></pre>
]]></description><link>https://actuarygarden.com/topic/21/sas-iml交互式数据处理及小实例</link><generator>RSS for Node</generator><lastBuildDate>Wed, 18 Nov 2026 14:08:48 GMT</lastBuildDate><atom:link href="https://actuarygarden.com/topic/21.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 May 2020 01:08:09 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to SAS IML交互式数据处理及小实例 on Mon, 25 May 2020 12:52:04 GMT]]></title><description><![CDATA[<pre><code>/*3 交互式矩阵语言 IML*/
/*3.1  概述*/
Proc IML;
	Sc=15.25;
	Vh={1 2};
	Print Sc;
	Print Vh;
Quit;
</code></pre>
<pre><code>/*3.2  数据集操作语句*/
Proc IML;
filename out 'user.matrix'; 
file out; 
    do i=1 to nrow(x); 
       do j=1 to ncol(x); 
          put (x[i,j]) 1.0 +2 @; 
       end; 
     	put;
	end; 
   closefile out;
QUIT;
</code></pre>
<pre><code>/*3.3  循环语句*/
/*3.4  分支语句*/
/*3.5  CALL语句*/
/*3.5  实例*/

/*实例1：方程组求解*/

PROC IML;
		A={2 3 1, 4 -1 2, 3 -1 1};
		b={10, 13,8};
		X=INV(A)*b;
		PRINT A b X;
QUIT;
</code></pre>
<pre><code>/*	实例2：非线性方程的迭代求解*/
PROC IML;
  	maxiter=50; /* 定义最大迭代次数 */ 
    converge=.000001; /* 定义收敛精度*/ 
       /* 定义待求解函数 */ 
start fun; 
      f= x**3-x+2; 
   finish fun; 
       /* 定义导函数 */ 
   start deriv; 
      df=3*x**2-1; 
   finish deriv; 
start newton; 
      run fun;          
      do iter=1 to maxiter  /* 迭代直到最大迭代次数 */ 
      while(max(abs(f))&gt;converge);            /* 收敛则提前退出 */ 
         run deriv;                /* 计算导函数 */ 
         delta=f/df;      /* 计算增量 */ 
         x=x-delta;                    /* 更新值 */ 
         run fun;                      /* 计算函数值 */ 
     end; 
   finish newton; 
do; 
      print "Solving the equation:" ,; 
      x=-1;     /* 赋初值 */ 
      run newton; 
	  iter=iter-1;
	  print x f iter; 
	  if iter&gt;maxiter then print 'Not converge!';
   end;
QUIT;
</code></pre>
<pre><code>/*实例3:把环比指数转化为定基指数*/
data a;
input id index;
cards;
1 100
1 93
1 103
1 97
2 100
2 97
2 116
2 98
run;
proc iml;
use a;
read all into mat;
index=j(8,1,1);
index[1]=mat[1,2];
do i=2 to 8 by 1;
   if (mat[i,1]=mat[i-1,1]) then index[i]=index[i-1]*mat[i,2];
   else index[i]=mat[i,2]; 
end;
 print index;
create b from index;
append from index;
close b;
run;
</code></pre>
]]></description><link>https://actuarygarden.com/post/54</link><guid isPermaLink="true">https://actuarygarden.com/post/54</guid><dc:creator><![CDATA[谢远涛]]></dc:creator><pubDate>Mon, 25 May 2020 12:52:04 GMT</pubDate></item></channel></rss>