<?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: Reordering a variables in a data set with 150 columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482661#M286900</link>
    <description>&lt;P&gt;There's only a very few reasons to do this, most of the time you are wasting your time. So don't do this. If you need things in a specific order for output reasons, PROC PRINT, PROC REPORT, PROC TABULATE all allow you to specify the order the variables appear in your output, regardless of the order of the variables in the data set. REPEATING: don't do this.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jul 2018 00:50:05 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-07-31T00:50:05Z</dc:date>
    <item>
      <title>Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482654#M286898</link>
      <description>&lt;P&gt;I have a data set with the following 151 columns:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;StudentID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exam1&lt;/P&gt;&lt;P&gt;Exam2&lt;/P&gt;&lt;P&gt;Exam3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Exam50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date1&lt;/P&gt;&lt;P&gt;Date2&lt;/P&gt;&lt;P&gt;Date3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Date50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Score1&lt;/P&gt;&lt;P&gt;Score2&lt;/P&gt;&lt;P&gt;Score3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Score50&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question: How do I reorder this large set of variables as follows -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;StudentID&lt;/P&gt;&lt;P&gt;Exam1&lt;/P&gt;&lt;P&gt;Date1&lt;/P&gt;&lt;P&gt;Score1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Exam2&lt;/P&gt;&lt;P&gt;Date2&lt;/P&gt;&lt;P&gt;Score2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Exam50&lt;/P&gt;&lt;P&gt;Date50&lt;/P&gt;&lt;P&gt;Score50?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am at the level of a beginner. Is there a way I can reorder using RETAIN, but without manually entering the variables in the RETAIN statement?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 00:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482654#M286898</guid>
      <dc:creator>whiteco</dc:creator>
      <dc:date>2018-07-31T00:07:08Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482655#M286899</link>
      <description>&lt;P&gt;you can query sashelp.vcolumn or dicitonary.columns&lt;/P&gt;&lt;P&gt;extract the number from each into a new var&lt;/P&gt;&lt;P&gt;sort according to new var numbers&lt;/P&gt;&lt;P&gt;load into a macro var separated by ' '&lt;/P&gt;&lt;P&gt;call the macro var in retain&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;wish i could demonstrate , but feeling too lazy and tired. My apologies&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 00:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482655#M286899</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-31T00:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482661#M286900</link>
      <description>&lt;P&gt;There's only a very few reasons to do this, most of the time you are wasting your time. So don't do this. If you need things in a specific order for output reasons, PROC PRINT, PROC REPORT, PROC TABULATE all allow you to specify the order the variables appear in your output, regardless of the order of the variables in the data set. REPEATING: don't do this.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 00:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482661#M286900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-31T00:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482664#M286901</link>
      <description>&lt;P&gt;It may be easier to transpose your data, via PROC TRANSPOSE/Data step, add a new variable with an order and then retranspose. Though I suspect you may find a long form to work with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Heres a tutorial on going wide to long.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/reshaping-data-wide-to-long-using-a-data-step/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 01:07:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482664#M286901</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-31T01:07:50Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482667#M286902</link>
      <description>&lt;P&gt;You don't have to enter the variable names manually into a RETAIN statement.&amp;nbsp; A reasonably straightforward macro can do that for you.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro varlist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%local k;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%do k=1 %to 50;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; Exam&amp;amp;k&amp;nbsp; Date&amp;amp;k&amp;nbsp; Score&amp;amp;k&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;%end;&lt;/P&gt;
&lt;P&gt;%mend varlist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;retain StudentID %varlist;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You end up with the same list of variables in the RETAIN statement, but the computer does the work of generating the list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 01:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482667#M286902</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-31T01:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482678#M286903</link>
      <description>&lt;P&gt;See&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s reply for an answer.&lt;/P&gt;
&lt;P&gt;Unless you have a very good reason, you'd be much better off having just&amp;nbsp;4 columns: ID, EXAM, DATE, SCORE&lt;/P&gt;
&lt;P&gt;A long table is much much easier to work with than a wide one,&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 02:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482678#M286903</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-07-31T02:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering a variables in a data set with 150 columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482845#M286904</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;See&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;'s reply for an answer.&lt;/P&gt;
&lt;P&gt;Unless you have a very good reason, you'd be much better off having just&amp;nbsp;4 columns: ID, EXAM, DATE, SCORE&lt;/P&gt;
&lt;P&gt;A long table is much much easier to work with than a wide one,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And possibly an ORDER, or similarly named,&amp;nbsp;variable to keep track of exam1, exam2 etc.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jul 2018 14:52:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-a-variables-in-a-data-set-with-150-columns/m-p/482845#M286904</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-07-31T14:52:26Z</dc:date>
    </item>
  </channel>
</rss>

