How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

Header 1Header 2Header 3
1
0.21
0.50.91
0.800.28

So I have something like this but it's a very big one (100K*100K).

Header 1Header 2Header 3
10.20.5
0.210.9
0.50.91

I hope to get the spces all filled up with a correlation or simmilarity whatever becomes

I know proc iml can do this quickly but my sas just doesn't have proc iml comes with it.

Please let me know anyway I can solve the problem.

I aprpeciate!!

-Sarah


Accepted Solutions
Solution
‎12-06-2012 06:46 PM
Respected Advisor
Posts: 3,777

Re: How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

100k variables is a lot!  This works for 10,000 variables and doesn't take too long.  I tried it with 100,000 but did not want to wait for it to finish.

This method is simple flip the data over, so that you get an upper trianglar.  Then update the lower with the upper.  Requires an observation index variable (_obs_).

data head;
   array header[10000];
   do _obs_ = 1 to dim(header);
      do i = 1 to _obs_;
         if i = _obs_ then header=1;
        
else header=ranuni(1);
         end;
     
output;
     
end;
  
run;

proc transpose data=head out=head2 prefix=header;
   copy _obs_;
   var header:;
   run;

data head3;
   update head head2;
   by _obs_;
   run;

View solution in original post


All Replies
Solution
‎12-06-2012 06:46 PM
Respected Advisor
Posts: 3,777

Re: How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

100k variables is a lot!  This works for 10,000 variables and doesn't take too long.  I tried it with 100,000 but did not want to wait for it to finish.

This method is simple flip the data over, so that you get an upper trianglar.  Then update the lower with the upper.  Requires an observation index variable (_obs_).

data head;
   array header[10000];
   do _obs_ = 1 to dim(header);
      do i = 1 to _obs_;
         if i = _obs_ then header=1;
        
else header=ranuni(1);
         end;
     
output;
     
end;
  
run;

proc transpose data=head out=head2 prefix=header;
   copy _obs_;
   var header:;
   run;

data head3;
   update head head2;
   by _obs_;
   run;
Trusted Advisor
Posts: 1,300

Re: How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

I do not think a 100k X 100k matrix will be possible to do this way, I think it tops out somewhere above 16k X 16k.  Not sure if this is some limit on FCMP.

proc fcmp;

array x[10000,10000] /nosymbols;

t=time();

/* fill lower triangle */

do a=1 to 10000;

  do b=1 to a;

   x[a,b]=1 ++ a +- b ;

  end;

end;

d=time()-t;

put 'fill=' d 'seconds';

t=time();

/* fill upper triangle */

do a=1 to 10000 by 1;

  do b=10000 to a by +-1;

   x[a,b]=x[b,a];

  end;

end;

d=time()-t;

put 'transpose=' d 'seconds';

t=time();

rc=write_array('all',x);

d=time()-t;

put 'write=' d 'seconds';

run;

fill= 1.0461549759 seconds

transpose= 2.3460171223 seconds

write= 7.7724590302 seconds

Contributor
Posts: 46

Re: How to convert a lower triagle form matrix to a symmetric one "WITHOUT" proc iml?

I appreciate!!!!!!!!!!!!!!!!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 226 views
  • 3 likes
  • 3 in conversation