<?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: Why is proc transpose (wide to long) creating extra columns? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907701#M40601</link>
    <description>&lt;P&gt;Now I understood it. Yes, you rightly pointed out that by variable is not unique. It helped me to solve my issue. Thanks once again.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
    <pubDate>Wed, 13 Dec 2023 04:53:07 GMT</pubDate>
    <dc:creator>DrAbhijeetSafai</dc:creator>
    <dc:date>2023-12-13T04:53:07Z</dc:date>
    <item>
      <title>Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557239#M9960</link>
      <description>&lt;P&gt;I am trying to perform a transpose from wide to long.&amp;nbsp; There are 27 variables that I am transposing.&amp;nbsp; The data looks essentially like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; &amp;nbsp;var1&amp;nbsp; &amp;nbsp;var2&amp;nbsp; var3 ... var27&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the past when I have done this transpose, the result looks like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; _name_&amp;nbsp; COL1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var27&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, today the result I am getting looks like this:&lt;/P&gt;&lt;P&gt;id&amp;nbsp; _name_&amp;nbsp; COL1&amp;nbsp; COL2&amp;nbsp; COL3&amp;nbsp; ... COL25&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; a&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; b&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; c&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; var27&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code I used:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc transpose data = data out = data_long ;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;by id;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;var var1 - var27;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I doing wrong here?&amp;nbsp; Why and I getting so many columns?&lt;/P&gt;&lt;P&gt;My variables are all consecutive in the data set and all are the same format- $8.&lt;/P&gt;&lt;P&gt;Using SAS 9.4 on Windows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 18:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557239#M9960</guid>
      <dc:creator>miriamhartig</dc:creator>
      <dc:date>2019-05-08T18:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557241#M9962</link>
      <description>&lt;P&gt;The BY variable values are not unique.&amp;nbsp; The number of variables ("columns") created is equal to the largest number of observations ("rows") for any single BY group.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 18:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557241#M9962</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-08T18:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557246#M9965</link>
      <description>&lt;P&gt;That makes sense Tom, thank you.&amp;nbsp; So removing duplicate IDs should solve this then right?&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 19:02:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557246#M9965</guid>
      <dc:creator>miriamhartig</dc:creator>
      <dc:date>2019-05-08T19:02:17Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557275#M9970</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250904"&gt;@miriamhartig&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That makes sense Tom, thank you.&amp;nbsp; So removing duplicate IDs should solve this then right?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, no and maybe.&lt;/P&gt;
&lt;P&gt;The issue may then become which of the value set you want for the original combination of values for var1 - varn. If all of the Id have the same var1 - varn then&amp;nbsp;selection of which observation (unique id value) to keep and transform&amp;nbsp;is easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what if, for some reason we can't tell at this point you want the var1 value from the first record with Id=1 and the var2 value from the&amp;nbsp;4th record with Id=1 (and so on for other vars)? Then how to get a single ID for transpose may be a bit tricky.&lt;/P&gt;
&lt;P&gt;And if you really need all the values perhaps a manual transpose is in order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input id var1 $ var2 $ var3$;
datalines;
1 a b c
2 b c d
3 c d e
1 d e c
2 p d q
;
run;

data manualtrans (keep= id _name_ value);
   set example;
   array v var1-var3;
   length _name_ $10.;
   do i = 1 to dim(v);
      _name_ = vname(v[i]);
      value = v[i];
      output;
   end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 19:59:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557275#M9970</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-08T19:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557302#M9975</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250904"&gt;@miriamhartig&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;That makes sense Tom, thank you.&amp;nbsp; So removing duplicate IDs should solve this then right?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Or adding another variable (or more) to the BY statement so that each row is identified uniquely.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fix; 
  set have ;
  by idvar ;
  if first.idvar then row_num=0;
  row_num+1;
run;
proc transpose data=fix .... ;
  by idvar row_num;
  ....
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 21:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/557302#M9975</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-08T21:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907522#M40595</link>
      <description>&lt;P&gt;Thank you. Still my problem is not solved on which I am working, but this answer has given me a good hint. Thanks once again.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 12:40:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907522#M40595</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2023-12-12T12:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907701#M40601</link>
      <description>&lt;P&gt;Now I understood it. Yes, you rightly pointed out that by variable is not unique. It helped me to solve my issue. Thanks once again.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 04:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907701#M40601</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2023-12-13T04:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907702#M40602</link>
      <description>&lt;P&gt;Yes, it has at least helped me.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 04:53:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/907702#M40602</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2023-12-13T04:53:44Z</dc:date>
    </item>
    <item>
      <title>Re: Why is proc transpose (wide to long) creating extra columns?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/917529#M41066</link>
      <description>&lt;P&gt;I would like to post it again that the solution given by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;is wonderful. He said that the records are not unique and that gave me hint and I was able to find out a variable which was not previously included in the by statement of proc transpose and this problem was solved. I am posting here again because again I faced the same problem and it got solved by addition of a variable in by statement which was not added previously. So the solution to this kind of problem is mostly - to find out the variable which is not added in by statement of proc transpose and to add it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Dr. Abhijeet Safai&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 04:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Why-is-proc-transpose-wide-to-long-creating-extra-columns/m-p/917529#M41066</guid>
      <dc:creator>DrAbhijeetSafai</dc:creator>
      <dc:date>2024-02-23T04:57:49Z</dc:date>
    </item>
  </channel>
</rss>

