<?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 data for muti cols and rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947012#M370803</link>
    <description>&lt;P&gt;This question gets asked a lot.&amp;nbsp; &amp;nbsp; Using PROC transpose you will need to transpose to "full-tall" then flatten.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input group $ order  L1  L2;
   datalines;
A1 1 45 36 
A1 2 25 55 
A2 1  88 99 
A2 2 74 78
A3 1 4 . 25
A3 2  88 99 
B4 1 78 65 
B4 2 . . 
;
run;

proc print;
   run;
proc transpose data=have out=tall;
   by group order;
   var L:;
   run;
proc sort;
   by group _name_ order; /*your variable order*/
   run;
proc print;
   run;
proc transpose data=tall out=wider(drop=_name_) delim=_;
   by group;
   var col1;
   id _name_ order;
   run;
proc 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="Capture.PNG" style="width: 229px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101114iE6CF5C3F9F5C1588/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 15:41:04 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2024-10-10T15:41:04Z</dc:date>
    <item>
      <title>How to transpose data for muti cols and rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/946988#M370797</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I try to modify my 'Have' data to 'Want'.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried and it looks like I need to do subset and then merge, or transpose then subset and merge.&lt;/P&gt;
&lt;P&gt;Is it a smart way to do it all at once? If you were me, what will you do?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="stataq_2-1728568287578.png" style="width: 652px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101109i1935F15CD10D6FCC/image-dimensions/652x176?v=v2" width="652" height="176" role="button" title="stataq_2-1728568287578.png" alt="stataq_2-1728568287578.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input group   $ order  L1  L2 ;
datalines;
A1 1 45 36 
A1 2 25 55 
A2 1  88 99 
A2 2 74 78
A3 1 4 . 25
A3 2  88 99 
B4 1 78 65 
B4 2 . . 
;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2024 13:52:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/946988#M370797</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-10-10T13:52:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose data for muti cols and rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/946991#M370798</link>
      <description>&lt;P&gt;Wide data sets are difficult to work with, compared to the same data in a long data set. So without a very good reason why you need this wide data set, I would say don't bother.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of concentrating on the technical problem of transposing, better would be if you explain the problem from a big picture point of view; and explain what you will do next after you transpose.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 14:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/946991#M370798</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-10T14:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose data for muti cols and rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947012#M370803</link>
      <description>&lt;P&gt;This question gets asked a lot.&amp;nbsp; &amp;nbsp; Using PROC transpose you will need to transpose to "full-tall" then flatten.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input group $ order  L1  L2;
   datalines;
A1 1 45 36 
A1 2 25 55 
A2 1  88 99 
A2 2 74 78
A3 1 4 . 25
A3 2  88 99 
B4 1 78 65 
B4 2 . . 
;
run;

proc print;
   run;
proc transpose data=have out=tall;
   by group order;
   var L:;
   run;
proc sort;
   by group _name_ order; /*your variable order*/
   run;
proc print;
   run;
proc transpose data=tall out=wider(drop=_name_) delim=_;
   by group;
   var col1;
   id _name_ order;
   run;
proc 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="Capture.PNG" style="width: 229px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/101114iE6CF5C3F9F5C1588/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 15:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947012#M370803</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-10-10T15:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose data for muti cols and rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947013#M370804</link>
      <description>&lt;P&gt;data test;&lt;BR /&gt;input group $ order L1 L2;&lt;BR /&gt;datalines;&lt;BR /&gt;A1 1 45 36 &lt;BR /&gt;A1 2 25 55 &lt;BR /&gt;A2 1 88 99 &lt;BR /&gt;A2 2 74 78&lt;BR /&gt;A3 1 4 . 25&lt;BR /&gt;A3 2 88 99 &lt;BR /&gt;B4 1 78 65 &lt;BR /&gt;B4 2 . . &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=test out=test_L1 prefix=L1_;&lt;BR /&gt;by group;&lt;BR /&gt;var L1;&lt;BR /&gt;id order;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=test out=test_L2 prefix=L2_;&lt;BR /&gt;by group;&lt;BR /&gt;var L2;&lt;BR /&gt;id order;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test_m;&lt;BR /&gt;merge test_L1 test_L2;&lt;BR /&gt;by group;&lt;BR /&gt;keep group L:;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=test_m;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 15:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947013#M370804</guid>
      <dc:creator>JOL</dc:creator>
      <dc:date>2024-10-10T15:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to transpose data for muti cols and rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947082#M370815</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input group   $ order  L1  L2 ;
datalines;
A1 1 45 36 
A1 2 25 55 
A2 1  88 99 
A2 2 74 78
A3 1 4 . 25
A3 2  88 99 
B4 1 78 65 
B4 2 . . 
;
run;

proc sql noprint;
select max(n) into :n from (select count(*) as n from have group by group);
quit;
proc summary data=have nway;
class group;
output out=want idgroup(out[&amp;amp;n.] (L1 L2)=);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Oct 2024 02:21:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-transpose-data-for-muti-cols-and-rows/m-p/947082#M370815</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-10-11T02:21:13Z</dc:date>
    </item>
  </channel>
</rss>

