<?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: Transpose Column into rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667105#M199712</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have worked on a logic but it looks too long.&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Split the table into two tables based on group. In my real example table there are 7 groups.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Then bring all the three columns values into one column&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Use distinct and transpose.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Append all table&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Let me know if there is better approach.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The length does not matter, but readability and maintainability do. So please post the code you have actually used, so that we can suggest improvements.&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 05:48:21 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-07-06T05:48:21Z</dc:date>
    <item>
      <title>Transpose Column into rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667058#M199688</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;Below is my dataset. This is company hierarchy level data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Owner&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Owner1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Owner2&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Radha&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jane&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Jack&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Chang&lt;/P&gt;&lt;P&gt;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Vijay&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ajay&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Uma&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sandeep&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Peter&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Brian&lt;/P&gt;&lt;P&gt;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Peter&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Lance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tom and Jane are level 7 Managers, Sam and Jack Reports to Tom and then there are people under Sam and Jack. I need the below data as my output&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Owner1&amp;nbsp; &amp;nbsp;Owner2&amp;nbsp; Owner3&amp;nbsp; &amp;nbsp;Owner4&amp;nbsp; Owner5&amp;nbsp; Owner6&amp;nbsp; &amp;nbsp; &amp;nbsp;Owner7&amp;nbsp; &amp;nbsp; &amp;nbsp;Owner8&lt;/P&gt;&lt;P&gt;Tom&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sam&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Jack&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Radha&amp;nbsp; &amp;nbsp; &amp;nbsp; Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; Chang&lt;/P&gt;&lt;P&gt;Jane&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Peter&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Vijay&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;uma&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Ajay&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Sandeep&amp;nbsp; &amp;nbsp; Brian&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the Name variable grouping (first column, I want everyone under Tom and those employees under his hierarchy. Similarly for Jane.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have worked on a logic but it looks too long.&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Split the table into two tables based on group. In my real example table there are 7 groups.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Then bring all the three columns values into one column&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Use distinct and transpose.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Append all table&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Let me know if there is better approach.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Jul 2020 20:46:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667058#M199688</guid>
      <dc:creator>sameer112217</dc:creator>
      <dc:date>2020-07-05T20:46:55Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Column into rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667063#M199689</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (Owner           Owner1              Owner2) (:$10.);
cards;

Tom               Sam                  Radha  

Tom               Sam                  Jane

Tom               Jack                  Chang

Jane              Vijay                  Ajay

Jane              Uma                  Sandeep

Jane              Peter                 Brian

Jane              Peter                 Lance
;


data want;
  set have;
  by Owner notsorted;
  if first.Owner then do; _n+1;	k=0;end;
  array t Owner Owner1   Owner2;
  array j(999)$ _temporary_;
  do over t;
   if t in j then continue;
   k+1;
   n=_i_;
   v=t;
   output;
   j(k)=t;
  end;
  if last.Owner then call missing(of j(*));
  keep _n Owner n v;
run;

proc sort data=want out=_want ;
by _n  n ;
run;

proc transpose data=_want out=final__want(drop=Owner _name_) prefix=Owner;
by Owner notsorted;
var v;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Jul 2020 23:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667063#M199689</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-07-05T23:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Column into rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667105#M199712</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/89720"&gt;@sameer112217&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have worked on a logic but it looks too long.&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Split the table into two tables based on group. In my real example table there are 7 groups.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Then bring all the three columns values into one column&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Use distinct and transpose.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;&lt;STRONG&gt;Append all table&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Let me know if there is better approach.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The length does not matter, but readability and maintainability do. So please post the code you have actually used, so that we can suggest improvements.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 05:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667105#M199712</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-07-06T05:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose Column into rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667122#M199720</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
  set have;
  array owners Owner Owner1-Owner2;
  do level=1 to dim(Owners);
    sub=Owners(level);
    if not missing(sub) then 
      output;
    end;
  keep Owner level sub;
run;
  
proc sort nodupkey data=long;
  by owner level sub;
run;

proc transpose data=long out=want(drop=_name_ Owner) prefix=Owner;
  by owner;
  var sub;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 08:44:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-Column-into-rows/m-p/667122#M199720</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-07-06T08:44:35Z</dc:date>
    </item>
  </channel>
</rss>

