I have data(data1) in following format :
obs | A | B | C |...
1 | 10 | 20 | 40 |...
2 | 05 | 24 | 45 |...
3 | 67 | 45 | 152 |...
:
I want to pass each columns to call svd which is available in proc iml.
and also want to store values of call svd in another data for further use...
I have tried using ...
proc iml;
use data1;
read all;
call svd(U, D, V, A);
call svd(U, D1, V, B);
call svd(U, D2, V, C);
:
call symputx("result1", D);
call symputx("result2", D1);
call symputx("result3", D2);
:
quit;
%put &result1
&result2
&result3;
data data2;
array a{*} a1-aN;
a1=&result1;
a2=&result2;
a3=&result3;
:
run;
Can you help me to run this dynamically?
You can do something like this
data data1;
input A B C;
datalines;
10 20 40
05 24 45
67 45 152
;
proc iml;
use data1;
read all var _NUM_ into X;
close data1;
D=j(nrow(X), 1, .);
do i=1 to ncol(X);
call svd(U, temp, V, X[ ,i]);
D[i]=temp;
end;
create data2 var {D};
append;
close data2;
quit;
You can do something like this
data data1;
input A B C;
datalines;
10 20 40
05 24 45
67 45 152
;
proc iml;
use data1;
read all var _NUM_ into X;
close data1;
D=j(nrow(X), 1, .);
do i=1 to ncol(X);
call svd(U, temp, V, X[ ,i]);
D[i]=temp;
end;
create data2 var {D};
append;
close data2;
quit;
This seems like a lot of work to compute the norm of a vector. When you pass a vector to the SVD, the singular value is the (uncorrected) sum of squares of the elements, which is equal to the vector (L2) norm, which you can compute by using the NORM function::
proc iml;
use sashelp.class;
read all var {height weight age} into X;
close;
D = j(ncol(X), 1, .);
norm = j(ncol(X), 1, .);
do i=1 to ncol(X);
call svd(U, Q, V, X[ ,i]);
D[i]=Q;
norm[i] = norm(X[ ,i]); /* more efficient: use NORM of each col */
end;
print D norm;
Even more efficient: the L2 norm is simply the sqrt of the sum of squares of each column, so the most efficient computation is to use the ## subscript reduction operator on each column:
D = sqrt( X[##, ] ); /* most efficient: sqrt(SSQ) of each column */
print D;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.
Find more tutorials on the SAS Users YouTube channel.