<?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 Transpose in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330056#M73958</link>
    <description>&lt;P&gt;Hi Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set like below (input) and need your help in getting the output dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data input;&lt;BR /&gt;input ColumnA $ ColumnB $ ColumnC $ ColumnD$ Value;&lt;BR /&gt;cards;&lt;BR /&gt;A B C A1 1&lt;BR /&gt;A B C A1 2&lt;BR /&gt;A B C A1 3&lt;BR /&gt;A B C A1 4&lt;BR /&gt;A B C A2 1&lt;BR /&gt;A B C A2 2&lt;BR /&gt;A B C A2 3&lt;BR /&gt;A B C A2 4&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data output;&lt;BR /&gt;input ColumnA $ ColumnB $ ColumnC $ A1 A2;&lt;BR /&gt;cards;&lt;BR /&gt;A B C 1 1&lt;BR /&gt;A B C 2 2&lt;BR /&gt;A B C 3 3&lt;BR /&gt;A B C 4 4&lt;BR /&gt;;&lt;/P&gt;</description>
    <pubDate>Sun, 05 Feb 2017 22:08:05 GMT</pubDate>
    <dc:creator>sascodequestion</dc:creator>
    <dc:date>2017-02-05T22:08:05Z</dc:date>
    <item>
      <title>Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330056#M73958</link>
      <description>&lt;P&gt;Hi Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set like below (input) and need your help in getting the output dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data input;&lt;BR /&gt;input ColumnA $ ColumnB $ ColumnC $ ColumnD$ Value;&lt;BR /&gt;cards;&lt;BR /&gt;A B C A1 1&lt;BR /&gt;A B C A1 2&lt;BR /&gt;A B C A1 3&lt;BR /&gt;A B C A1 4&lt;BR /&gt;A B C A2 1&lt;BR /&gt;A B C A2 2&lt;BR /&gt;A B C A2 3&lt;BR /&gt;A B C A2 4&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data output;&lt;BR /&gt;input ColumnA $ ColumnB $ ColumnC $ A1 A2;&lt;BR /&gt;cards;&lt;BR /&gt;A B C 1 1&lt;BR /&gt;A B C 2 2&lt;BR /&gt;A B C 3 3&lt;BR /&gt;A B C 4 4&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 22:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330056#M73958</guid>
      <dc:creator>sascodequestion</dc:creator>
      <dc:date>2017-02-05T22:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330058#M73959</link>
      <description>&lt;P&gt;YOu have not sufficiently described the rules by which you want to associate the data records.&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Are you associating records within columna/columnb/columnc groups?&lt;/LI&gt;
&lt;LI&gt;Are you pairing columnd='A1' and columnd='A2' records?&lt;/LI&gt;
&lt;LI&gt;If so, are they associated by position within a/b/c?&amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;Do you always expect the same number of A1's and A2's?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Please try to avoid mindreading requirements.&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 22:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330058#M73959</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-05T22:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330062#M73961</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for your response.&lt;/P&gt;&lt;P&gt;1.The total number of observations should be devided into 2 groups, which is based on the values of the coulmnD(A1 and A2)&lt;/P&gt;&lt;P&gt;2. The observations &amp;nbsp;should be grouped based on ColumnA,columnB, ColumnC and columnD&lt;/P&gt;&lt;P&gt;3. The Values in the columnD should become new coulmns, for example in the above example we have two different values A1 and A2 so we should get 2 new columns in the output called A1 and A2&lt;/P&gt;&lt;P&gt;3. Column A1 and A2 &amp;nbsp;no need to have same rows. The total number of observation are going to be equal to the &amp;nbsp;higher number of observations in any group. &amp;nbsp;For example if group A1 contains 5 and A2 contains 3, so total number of obs will be equal to 5 and column A2 will have values 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this is clear&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 22:40:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330062#M73961</guid>
      <dc:creator>sascodequestion</dc:creator>
      <dc:date>2017-02-05T22:40:25Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330063#M73962</link>
      <description>&lt;P&gt;You would have to create new variables to account for what you want. Given your example you could use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data input;
input ColumnA $ ColumnB $ ColumnC $ ColumnD $ Value;
cards;
A B C A1 1
A B C A1 2
A B C A1 3
A B C A1 4
A B C A2 1
A B C A2 2
A B C A2 3
A B C A2 4
;

data need;
  set input;
  if mod(_n_,4) eq 0 then x=4;
  else x=mod(_n_,4);
run;

proc sort data=need;
  by ColumnA ColumnB ColumnC x ColumnD;
run;

data need;
  set need;
  if mod(_n_,2) eq 1 then group+1;
run;

proc transpose data=need out=want (drop= group _name_);
  by ColumnA ColumnB ColumnC Group;
  var value;
  id ColumnD;
run;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Feb 2017 23:10:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330063#M73962</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-05T23:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330101#M73982</link>
      <description>&lt;P&gt;Assuming (1) your data are sorted by columna/columnb/columnc and (2) columnd='A1' or 'A2', then you can use a MERGE process as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=n n1 n2 columnd);
  n1=0; n2=0;
  do until (last.columnc);
    set input (keep=columna columnb columnc columnd);
    by columna columnb columnc;
    if      columnd='A1' then n1=n1+1;
    else if columnd='A2' then n2=n2+1;
  end;

  do N=1 by 1 until (last.columnc);
    merge input (in=in1 where=(columnd='A1') rename=(value=a1))
          input (in=in2 where=(columnd='A2') rename=(value=a2));
    by columna columnb columnc;
    if n&amp;gt;n1 then a1=0;
    if n&amp;gt;n2 then a2=0;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that N1&amp;nbsp;and N2 are the counts of A1 and A2 records respectively.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 05:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose/m-p/330101#M73982</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-02-06T05:55:32Z</dc:date>
    </item>
  </channel>
</rss>

