<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Reshaping data in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464578#M4186</link>
    <description>&lt;P&gt;Please provide a sample data you have and the result your looking for.&lt;/P&gt;</description>
    <pubDate>Wed, 23 May 2018 21:12:12 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-05-23T21:12:12Z</dc:date>
    <item>
      <title>Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464566#M4185</link>
      <description>&lt;P&gt;I want to reshape a matrix created in IML and convert it to a sas dataset while retaining the column and row names. For example,&amp;nbsp; suppose I have an N by N matrix with row and column names.&amp;nbsp; The end product I want is a sas dataset with 3 variables.&amp;nbsp; The first&amp;nbsp;variable is created by stacking the columns of the original matrix (implying the dataset has N^2 observations).&amp;nbsp; The second&amp;nbsp;variable is a character variable with the appropriate column name from the original matrix.&amp;nbsp; The third column is a character variable with the appropriate row name from the original matrix.&amp;nbsp; Is this possible?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 20:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464566#M4185</guid>
      <dc:creator>coder1</dc:creator>
      <dc:date>2018-05-23T20:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464578#M4186</link>
      <description>&lt;P&gt;Please provide a sample data you have and the result your looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 21:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464578#M4186</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-05-23T21:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464582#M4187</link>
      <description>&lt;P&gt;The matrix as created in IML is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 2&lt;/P&gt;&lt;P&gt;3 4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The column names are c1 and c2;&lt;/P&gt;&lt;P&gt;The row names are r1 and r2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end result is a sas dataset that looks like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 r1 c1&lt;/P&gt;&lt;P&gt;3 r2 c1&lt;/P&gt;&lt;P&gt;2 r1 c2&lt;/P&gt;&lt;P&gt;4 r2 c2&lt;/P&gt;</description>
      <pubDate>Wed, 23 May 2018 21:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464582#M4187</guid>
      <dc:creator>coder1</dc:creator>
      <dc:date>2018-05-23T21:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464724#M4188</link>
      <description>&lt;P&gt;You really should post it at IML forum ,since it is about IML question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x={1 2,
   3 4};
row_name='r1':'r2';
col_name='c1':'c2';

row=row_name[row(x)];
col=col_name[col(x)];
value=colvec(x);

create want var{value row col};
append;
close;
quit;

proc print data=want noobs;run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 May 2018 12:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464724#M4188</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-24T12:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464763#M4189</link>
      <description>&lt;P&gt;Thanks Ksharp,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you explicitly define the row and column names as character&amp;nbsp;vectors, then as your code shows below, this is somewhat trivial.&amp;nbsp; I have a very large matrix with thousands of columns, and am pulling the variable names using varnames=contents().&amp;nbsp; Explicity defining them as character vectors would be impractical.&amp;nbsp; I created some code that I think does what I need it to (below).&amp;nbsp; I guess my only question is, can I always trust Varnames to be in the&amp;nbsp;right order&amp;nbsp;to specify the colnames and rownames of the correlation matrix as I do below?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;BR /&gt;use cdat1;&lt;BR /&gt;varNames = contents();&lt;BR /&gt;read all var _NUM_ into X[colname=varNames]; /* numerical data */&lt;BR /&gt;close cdat1;&lt;BR /&gt;&lt;BR /&gt;Z=corr(X,'Pearson','Pairwise');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mattrib Z rowname=varnames colname=varnames&lt;BR /&gt;spearman rowname=varnames colname=varnames;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;nn=varnames`;&lt;/P&gt;&lt;P&gt;create cmat from Z [colname=varNames];&lt;BR /&gt;append from Z;&lt;BR /&gt;close cmat;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create nmat from nn;&lt;BR /&gt;append from nn;&lt;BR /&gt;close nmat;&lt;/P&gt;&lt;P&gt;quit;&lt;BR /&gt;/*------------------------*/&lt;BR /&gt;data corrdat;&lt;BR /&gt;merge nmat cmat;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data corrdat;&lt;BR /&gt;set corrdat;&lt;BR /&gt;perm1=col1;&lt;BR /&gt;drop col1;&lt;/P&gt;&lt;P&gt;proc sort data=corrdat;&lt;BR /&gt;by perm1;&lt;BR /&gt;&lt;BR /&gt;proc transpose data=corrdat out=corrdat1;&lt;BR /&gt;by perm1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464763#M4189</guid>
      <dc:creator>coder1</dc:creator>
      <dc:date>2018-05-24T14:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reshaping data</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464782#M4190</link>
      <description>&lt;P&gt;Yes, you can "trust&amp;nbsp;Varnames to be in the right order."&lt;/P&gt;
&lt;P&gt;You can also simplify your program by writing the rownames&amp;nbsp;directly instead of writing two data sets and merging the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create cmat from Z [colname=varNames rowname=varNames];&lt;BR /&gt;append from Z[rowname=varNames];&lt;BR /&gt;close cmat;&lt;/P&gt;</description>
      <pubDate>Thu, 24 May 2018 14:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Reshaping-data/m-p/464782#M4190</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-05-24T14:42:38Z</dc:date>
    </item>
  </channel>
</rss>

