<?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 to transpose many columns to one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772826#M245416</link>
    <description>&lt;P&gt;If you did want to use PROC TRANSPOSE I think you need to add a variable because your ID is repeated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set have;
by id;
if first.ID then counter=1;
else counter+1;
run;


proc transpose data=temp out=want prefix=record;
by ID counter;
var record1 record2 record3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 07 Oct 2021 17:35:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-07T17:35:47Z</dc:date>
    <item>
      <title>How to transpose many columns to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772816#M245410</link>
      <description>&lt;P&gt;Hello, I have a dataset I'm trying to reshape using proc transpose but I cant quite seem to figure it out&lt;/P&gt;&lt;P&gt;&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 id $ record1 $ record2 $ record3 $;
datalines;
A1 a15 n14
A1 a15 b12 b17
A1 a12 b18
A2 a29 a28 a21
A3 a34 a36 c34&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want this data to look like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id $ record $;&lt;BR /&gt;&lt;BR /&gt;A1 a15
A1 n14
A1 a15
A1 b12 
A1 b17
A1 a12
A1 b18
A2 a29
A2 a28 
A2 a21
A3 a34
A3 a36
A3 c34&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using proc transpose i get a set with multiple columns and i cant figure out how to get only one column. Does anyone have any tips on how to do this? Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772816#M245410</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2021-10-07T17:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose many columns to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772818#M245412</link>
      <description>&lt;PRE&gt;&lt;STRIKE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=want prefix=record;
by ID;
var record1-record3;
run;&lt;/CODE&gt;&lt;/STRIKE&gt;&lt;/PRE&gt;
&lt;P&gt;EDIT: In this case I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46466"&gt;@snoopy369&lt;/a&gt;&amp;nbsp;a data step is easier with the duplicate entries, otherwise you need to add a grouping variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Transposing data tutorials:&lt;BR /&gt;Long to Wide:&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-long-to-wide-using-the-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Wide to Long:&lt;/STRONG&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-wide-to-long-using-proc-transpose/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank" rel="noopener"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;And sometimes a double transpose is needed for extra wide data sets:&lt;BR /&gt;&lt;A href="https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd" target="_blank" rel="noopener"&gt;https://gist.github.com/statgeek/2321b6f62ab78d5bf2b0a5a8626bd7cd&lt;/A&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391589"&gt;@raddad34&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello, I have a dataset I'm trying to reshape using proc transpose but I cant quite seem to figure it out&lt;/P&gt;
&lt;P&gt;&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 id $ record1 $ record2 $ record3 $;
datalines;
A1 a15 n14
A1 a15 b12 b17
A1 a12 b18
A2 a29 a28 a21
A3 a34 a36 c34&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want this data to look like this:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id $ record $;&lt;BR /&gt;&lt;BR /&gt;A1 a15
A1 n14
A1 a15
A1 b12 
A1 b17
A1 a12
A1 b18
A2 a29
A2 a28 
A2 a21
A3 a34
A3 a36
A3 c34&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using proc transpose i get a set with multiple columns and i cant figure out how to get only one column. Does anyone have any tips on how to do this? Thank you.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772818#M245412</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-07T17:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose many columns to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772820#M245414</link>
      <description>&lt;P&gt;You should just do this in the data step - easier and faster than coercing PROC TRANSPOSE to do what you want!&amp;nbsp; Just make an array of your variables and then `output` new rows when you have a value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  set have;
  array recs record1-record3;
  do _i = 1 to dim(recs);
    if not missing(recs[_i]) then do;
    	record = recs[_i];
    	output;
    end;
  end;
  keep record id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772820#M245414</guid>
      <dc:creator>snoopy369</dc:creator>
      <dc:date>2021-10-07T17:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose many columns to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772826#M245416</link>
      <description>&lt;P&gt;If you did want to use PROC TRANSPOSE I think you need to add a variable because your ID is repeated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set have;
by id;
if first.ID then counter=1;
else counter+1;
run;


proc transpose data=temp out=want prefix=record;
by ID counter;
var record1 record2 record3;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Oct 2021 17:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772826#M245416</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-07T17:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose many columns to one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772829#M245419</link>
      <description>Thank you so much! this works perfectly!</description>
      <pubDate>Thu, 07 Oct 2021 17:45:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-many-columns-to-one/m-p/772829#M245419</guid>
      <dc:creator>raddad34</dc:creator>
      <dc:date>2021-10-07T17:45:53Z</dc:date>
    </item>
  </channel>
</rss>

