This example shows how
to pass a matrix as an argument within PROC IML. The example creates
a 4x5 matrix. Each cell is set to 10
x+
y+3, where
x is the row number and
y is the column number. For example, the cell at row 1 column 2 is
set to (10*1)+2+3, or 15.
The example invokes
several routines from the theoretical TRYMOD DLL. It uses the
changd
routine to add 100
x+10
y to each element, where
x is the C row number (0 through 3) and
y is the C column number (0 through 4). The first
argument to
changd
indicates what extra amount
to sum. The
changdx
routine works just like
changd
, except that it expects a transposed matrix.
The
changi
routine works like
changd
except that it expects a matrix of integers.
The
changix
routine works like
changdx
except that integers are expected.
Note: A maximum of three arguments
can be sent when invoking a DLL routine from PROC IML.
In this example, all
four matrices x1, x2, y1, and y2 should become set to the same values
after their respective MODULEIN calls. Here are the attribute table
entries:
routine changd module=trymod returns=long;
arg 1 input num format=rb8. byvalue;
arg 2 update num format=rb8.;
routine changdx module=trymod returns=long
transpose=yes;
arg 1 input num format=rb8. byvalue;
arg 2 update num format=rb8.;
routine changi module=trymod returns=long;
arg 1 input num format=ib4. byvalue;
arg 2 update num format=ib4.;
routine changix module=trymod returns=long
transpose=yes;
arg 1 input num format=ib4. byvalue;
arg 2 update num format=ib4.;
Here is the PROC IML
step:
proc iml;
x1 = J(4,5,0);
do i=1 to 4;
do j=1 to 5;
x1[i,j] = i*10+j+3;
end;
end;
y1= x1; x2 = x1; y2 = y1;
rc = modulein('changd',6,x1);
rc = modulein('changdx',6,x2);
rc = modulein('changi',6,y1);
rc = modulein('changix',6,y2);
print x1 x2 y1 y2;
run;
The following are the
results of the PRINT statement:
X1
20 31 42 53 64
130 141 152 163 174
240 251 262 273 284
350 361 372 383 394
X2
20 31 42 53 64
130 141 152 163 174
240 251 262 273 284
350 361 372 383 394
Y1
20 31 42 53 64
130 141 152 163 174
240 251 262 273 284
350 361 372 383 394
Y2
20 31 42 53 64
130 141 152 163 174
240 251 262 273 284
350 361 372 383 394