<?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: Data Transformation: Reshape Wide to Long in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567783#M159712</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129176"&gt;@renanm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;thanks for taking the time to help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're absolutely right. After deduping the file it worked as expected.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to learn duplicates should be eliminated before running this procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again !&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Knowing the cause is helpful. Often you may actually want multiple columns like that for some purposes.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2019 21:32:37 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-06-20T21:32:37Z</dc:date>
    <item>
      <title>Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567603#M159633</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to do a transformation which I though would be quite simple. After trying most approaches shared in this forum I'm still not getting the expected results so looking for some help/guidance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks like:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id tr1 tr2 tr3 tr4;
cards;
1 AAA BBB GGG FFF
2 DDD CCC AAA BBB
3 BBB AAA JJJ VVV
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only difference is my real data is that variable TRX goes from 1 to 125 (tr1....tr125).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like the data to look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input id tr;
cards;
1 AAA
1 BBB
1 GGG
1 FFF
2 DDD
2 CCC
2 AAA
2 BBB
3 BBB
3 AAA
3 JJJ
3 VVV
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In essence, instead of multiple columns I'd like multiple rows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following code seems to work in very similar cases but not working for this one:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=have_trans;
   by ID;
   var tr1-tr4;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This yield a dataset with the following columns:&lt;/P&gt;&lt;P&gt;ID _NAME_ COL1 COL2 COL3 COL4 COL5........&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I make it so that it yields only ID _NAME_ COL1 with all values previous in multiple columns contained in COL1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 13:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567603#M159633</guid>
      <dc:creator>renanm</dc:creator>
      <dc:date>2019-06-20T13:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567607#M159635</link>
      <description>&lt;P&gt;Works fine?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id tr1 $ tr2 $ tr3 $ tr4 $;
cards;
1 AAA BBB GGG FFF
2 DDD CCC AAA BBB
3 BBB AAA JJJ VVV
;
run;

proc transpose data=have out=have_trans(drop=_NAME_ rename=(COl1=tr));
   by ID;
   var tr1-tr4;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Jun 2019 13:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567607#M159635</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-20T13:14:14Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567616#M159638</link>
      <description>&lt;P&gt;Thanks for your response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had previously tried this, but unfortunately it doesn't work as expected even though it does work in&amp;nbsp;this sample dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, in my real data this returns the following structure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;TR COL2 COL3 COL4 COL5.....COL125&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure why the remaining columns continue to show up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the final data to&amp;nbsp;have only the following with all values contained in the variable TR:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;TR&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the support.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 14:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567616#M159638</guid>
      <dc:creator>renanm</dc:creator>
      <dc:date>2019-06-20T14:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567632#M159644</link>
      <description>&lt;P&gt;Please post the log of the step that created this structure.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 14:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567632#M159644</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-06-20T14:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567638#M159646</link>
      <description>&lt;P&gt;interestingly, I I just re-ran the same code on a smaller dataset (for speed purposes) and it now returns only up to COL3:&lt;/P&gt;&lt;P&gt;ID TR COL2 COL3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, here's the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;;*';*";*/;quit;run;&lt;BR /&gt;2 OPTIONS PAGENO=MIN;&lt;BR /&gt;3 %LET _CLIENTTASKLABEL='Tracking File';&lt;BR /&gt;4 %LET _CLIENTPROJECTPATH='';&lt;BR /&gt;5 %LET _CLIENTPROJECTNAME='';&lt;BR /&gt;6 %LET _SASPROGRAMFILE=;&lt;BR /&gt;7&lt;BR /&gt;8 ODS _ALL_ CLOSE;&lt;BR /&gt;9 OPTIONS DEV=ACTIVEX;&lt;BR /&gt;10 GOPTIONS XPIXELS=0 YPIXELS=0;&lt;BR /&gt;11 FILENAME EGSR TEMP;&lt;BR /&gt;12 ODS tagsets.sasreport13(ID=EGSR) FILE=EGSR&lt;BR /&gt;13 STYLE=HtmlBlue&lt;BR /&gt;14 STYLESHEET=(URL="file:///C:/Program%20Files/SASHome2/SASEnterpriseGuide/7.1/Styles/HtmlBlue.css")&lt;BR /&gt;15 NOGTITLE&lt;BR /&gt;16 NOGFOOTNOTE&lt;BR /&gt;17 GPATH=&amp;amp;sasworklocation&lt;BR /&gt;18 ENCODING=UTF8&lt;BR /&gt;19 options(rolap="on")&lt;BR /&gt;20 ;&lt;BR /&gt;NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR&lt;BR /&gt;21&lt;BR /&gt;22 GOPTIONS ACCESSIBLE;&lt;BR /&gt;23 proc transpose data=have out=want_trans (drop=_NAME_ rename=(COl1=tr));&lt;BR /&gt;24 by ID;&lt;BR /&gt;25 var TR0-TR125;&lt;BR /&gt;26 run;&lt;/P&gt;&lt;P&gt;NOTE: There were 15824 observations read from the data set WORK.HAVE.&lt;BR /&gt;NOTE: The data set WORK.WANT_TRANS has 276423 observations and 4 variables.&lt;BR /&gt;NOTE: PROCEDURE TRANSPOSE used (Total process time):&lt;BR /&gt;real time 0.10 seconds&lt;BR /&gt;cpu time 0.09 seconds&lt;/P&gt;&lt;P&gt;27&lt;BR /&gt;28 GOPTIONS NOACCESSIBLE;&lt;BR /&gt;29 %LET _CLIENTTASKLABEL=;&lt;BR /&gt;30 %LET _CLIENTPROJECTPATH=;&lt;BR /&gt;31 %LET _CLIENTPROJECTNAME=;&lt;BR /&gt;32 %LET _SASPROGRAMFILE=;&lt;BR /&gt;33&lt;BR /&gt;34 ;*';*";*/;quit;run;&lt;BR /&gt;35 ODS _ALL_ CLOSE;&lt;BR /&gt;36&lt;BR /&gt;37&lt;BR /&gt;38 QUIT; RUN;&lt;BR /&gt;39&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 14:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567638#M159646</guid>
      <dc:creator>renanm</dc:creator>
      <dc:date>2019-06-20T14:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567648#M159651</link>
      <description>&lt;P&gt;Examine your data. I will bet that you find that you have duplicate values of one or more values of ID.&lt;/P&gt;
&lt;P&gt;Example: ID=1 appears twice, so we get col1 and col2 , one column for each duplicate of id. So if your output includes COL25 then at least one value of ID is duplicated 25 times in the input set.&lt;/P&gt;
&lt;PRE&gt;data have;
input id tr1 $ tr2 $ tr3 $ tr4 $;
cards;
1 AAA BBB GGG FFF
1 DDD CCC AAA BBB
3 BBB AAA JJJ VVV
;
run;

proc transpose data=have out=have_trans;
   by id;
   var tr1-tr4;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 15:03:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567648#M159651</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-20T15:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567691#M159672</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;thanks for taking the time to help.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You're absolutely right. After deduping the file it worked as expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Glad to learn duplicates should be eliminated before running this procedure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again !&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 16:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567691#M159672</guid>
      <dc:creator>renanm</dc:creator>
      <dc:date>2019-06-20T16:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: Data Transformation: Reshape Wide to Long</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567783#M159712</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/129176"&gt;@renanm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;thanks for taking the time to help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're absolutely right. After deduping the file it worked as expected.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad to learn duplicates should be eliminated before running this procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again !&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Knowing the cause is helpful. Often you may actually want multiple columns like that for some purposes.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2019 21:32:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Transformation-Reshape-Wide-to-Long/m-p/567783#M159712</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-20T21:32:37Z</dc:date>
    </item>
  </channel>
</rss>

