Solved
Contributor
Posts: 46

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

1
0.21
0.50.91
0.800.28

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

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
Posts: 3,852

## 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_).

do _obs_ = 1 to dim(header);
do i = 1 to _obs_;
if i = _obs_ then header=1;

end;

output;

end;

run;

copy _obs_;
run;

by _obs_;
run;

All Replies
Solution
‎12-06-2012 06:46 PM
Posts: 3,852

## 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_).

do _obs_ = 1 to dim(header);
do i = 1 to _obs_;
if i = _obs_ then header=1;

end;

output;

end;

run;

copy _obs_;
run;

by _obs_;
run;
Posts: 1,318

## 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 and locked.