turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Transposing a matrix using a do loop to create a s...

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

10-28-2013 08:10 PM

Hello!

I have a lower triangular correlation matrix matrix in a data set. I need to turn this lower triangular correlation matrix (it is in a data set right) into a square symmetric correlation matrix. I was wondering the best way to do this? I tried using the following code, but unfortunately it just prints the symmetric data set to my output whereas, I need to print it to a new data set. I could also write a do loop; I have 19 variables, xGT1 through xGT19. Basically

I want xGT1 through xGT19 , so a 19x19 matrix. How could I do this? Because it's a correlation matrix, I just have 1's on the diagonal. Below is the code I used, using the sqrvech command. Any help is appreciated.

Thank you soooo much!

proc iml;

use pcorr1;

read all var _NUM_ into Dist;

close pcorr1;

d = vech(Dist) ;

Dist = sqrvech(d) ;

print Dist[format=7.5

i was thinking of doing something like

data new; set old;

array gt {19} xgt1 - xgt19;

for i = 1 to 19;

for j = 1 to 19;

if xgt{i,j} = . then xgt{i,j} = xgt{j,i};

but I am not sure.... here I don't have two indices for i and j, I just have one index.

thanks,Gina

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to ginak

10-28-2013 09:04 PM

Use transpose and update. I assume your data is a typical TYPE=CORR dataset :

**data have;****length _TYPE_ _NAME_ $8;****array c{4};****_TYPE_ = "CORR";****do i = 1 to dim(c);**** call missing(of c{*});**** _NAME_ = vname(c{i});**** do j = 1 to i-1;**** c{j} = 0.1*(i-j);**** end;**** c{i} = 1;**** output;**** end;****drop i j;****run;**

**proc transpose data=have out=havet; copy _TYPE_; run;**

**data want;****update have havet;****by _TYPE_ _NAME_;****run;**

PG

Message was edited by: PG - Added the code in red .

PG