BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kaushik1
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;

 

Rick_SAS
SAS Super FREQ

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;

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Multiple Linear Regression in SAS

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 802 views
  • 0 likes
  • 3 in conversation