<?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: How can I transpose a table like transposing a matrix? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815856#M322004</link>
    <description>&lt;P&gt;Yes, I want to know what analysis the person receiving the data is going to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, my standard advice is this: don't convert/transpose the data to that format. It is a less usable format, requiring more work to program from. It doesn't get any simpler than that!&lt;/P&gt;</description>
    <pubDate>Tue, 31 May 2022 14:51:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-05-31T14:51:45Z</dc:date>
    <item>
      <title>How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815835#M321995</link>
      <description>&lt;P&gt;I have a table that looks something like this (there are actually way more rows and columns than this):&lt;/P&gt;
&lt;P&gt;month&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;
&lt;P&gt;202101&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;202102&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make it look like this:&lt;/P&gt;
&lt;P&gt;var&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;202101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202102&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 14:21:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815835#M321995</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-05-31T14:21:35Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815846#M322000</link>
      <description>&lt;P&gt;Is your goal by doing this to have a report that can be printed or included in some sort of document?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or is your goal to create a SAS data set for further analysis? (If so, what analysis?)&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 14:33:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815846#M322000</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-31T14:33:31Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815852#M322001</link>
      <description>I'm trying to have that as a final dataset but I want it to be on SAS so I can directly email that table to someone</description>
      <pubDate>Tue, 31 May 2022 14:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815852#M322001</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-05-31T14:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815853#M322002</link>
      <description>&lt;P&gt;What is the purpose of having a data set in this format? What analyses will be done with it after you e-mail it to someone?&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 14:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815853#M322002</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-31T14:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815855#M322003</link>
      <description>I'm not going to do any further analysis. I just want to to email it directly without having to export into excel</description>
      <pubDate>Tue, 31 May 2022 14:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815855#M322003</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-05-31T14:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815856#M322004</link>
      <description>&lt;P&gt;Yes, I want to know what analysis the person receiving the data is going to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, my standard advice is this: don't convert/transpose the data to that format. It is a less usable format, requiring more work to program from. It doesn't get any simpler than that!&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 14:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815856#M322004</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-31T14:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815858#M322005</link>
      <description>Oh I see. The person receiving the email won't do any analysis. It's just meant to be a monthly report sort of thing. Just wanted to do this because if we leave it as it is, there'll be around 40 columns which isn't really that presentable.</description>
      <pubDate>Tue, 31 May 2022 14:53:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815858#M322005</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-05-31T14:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815859#M322006</link>
      <description>&lt;P&gt;So the goal is really to create a report from this data!&amp;nbsp;See &lt;A href="https://communities.sas.com/t5/forums/editpage/board-id/programming/message-id/322006" target="_self"&gt;Maxim 19&lt;/A&gt;, Long Beats Wide!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input month yymmn6.    a     b     c;
cards;
202101   1     2      1
202102   4     3      2
;

data long;
    set have;
    length variable $ 32;
    array vars a--c;
    do i=1 to dim(vars);
        variable=vname(vars(i));
        value=vars(i);
        output;
    end;
    drop a--c i;
run;

proc report data=long;
    columns variable month,value;
    define variable/group;
    define month/across format=yymmn6. order=internal;
    define value/sum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to back up a step, and apply Maxim 19, you should not be creating this data set in the format given; you should create it initially as a long data set and then all of these gymnastics to get it into a usable form are unnecessary.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 17:01:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815859#M322006</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-31T17:01:27Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815863#M322008</link>
      <description>some of the columns in the table I have also have character values so this doesn't seem to work in that case. Also, the column names aren't a, b, c, etc. They don't really follow a pattern like that</description>
      <pubDate>Tue, 31 May 2022 15:07:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815863#M322008</guid>
      <dc:creator>aalluru</dc:creator>
      <dc:date>2022-05-31T15:07:22Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815864#M322009</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm trying to have that as a final dataset but I want it to be on SAS so I can directly email that table to someone&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But your requested output is not a dataset.&amp;nbsp; It has MONTH values in the NAMES of the variables instead of a actual data.&amp;nbsp; They will not be able to use that format in any analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to make a report to send to someone?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It helps if you have an actual unique key for the orignal dataset.&amp;nbsp; If you don't have one then make one. You can then transpose into a workable format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data step1;
  row+1;
  set have;
run;

proc transpose data=have out=tall name=var;
  by row month;
  var a b c ;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can either make a report.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=tall;
  column var col1,month ;
  define var / group 'VAR';
  define month / across ' ';
  define col1 / sum ' ';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1654009502621.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71900i8C9F263E9E08BDE3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1654009502621.png" alt="Tom_0-1654009502621.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Or you can sort and transpose again.&amp;nbsp; But in that case you will not get "202101" as the column headers unless you have accidentally turned on VALIDVARNAME=ANY.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=tall;
  by var row;
run;

proc transpose data=tall out=want(drop=_name_);
  by var ;
  id month;
  var col1;
run;

proc&amp;nbsp;print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1654009638579.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71901iB7EE971546C882AF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1654009638579.png" alt="Tom_1-1654009638579.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 15:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815864#M322009</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-31T15:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815989#M322050</link>
      <description>&lt;P&gt;Just like SAS/IML did ? Or you want IML code ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input month yymmn6.    a     b     c;
cards;
202101   1     2      1
202102   4     3      2
;
proc transpose data=have out=tall name=var;
  var  a b c ;
  id month;
  format month yymmn6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Jun 2022 04:34:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/815989#M322050</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-01T04:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: How can I transpose a table like transposing a matrix?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/816000#M322055</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355241"&gt;@aalluru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a table that looks something like this (there are actually way more rows and columns than this):&lt;/P&gt;
&lt;P&gt;month&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;
&lt;P&gt;202101&amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;202102&amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to make it look like this:&lt;/P&gt;
&lt;P&gt;var&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;202101&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 202102&lt;/P&gt;
&lt;P&gt;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/P&gt;
&lt;P&gt;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Make your dataset "longer", then use PROC REPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=long;
by month;
var a--c; /* variable list by position, only the first and last variable needs to be named */
run;

proc report data=long;
column _name_ col1,month;
define _name_ / "var" group;
define col1 / "" analysis;
define month / "" across;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Wrap the report step into a proper ODS destination for later use as an email attachment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code is untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jun 2022 06:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-transpose-a-table-like-transposing-a-matrix/m-p/816000#M322055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-01T06:54:44Z</dc:date>
    </item>
  </channel>
</rss>

