<?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 Sorting (ordering) variables of a data set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147789#M29281</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set with over 500 variables, and they are unordered. Currently, by using Proc Contents, I extract the ordered list of variables, copy the list from the html output, paste it onto the Excel, delete the unnecessary columns, and copy again the list. Then, I do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (paste the list of variables..)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set mydata;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any other method to do this with avoiding copying and pasting things? Thanks! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Nov 2013 22:17:36 GMT</pubDate>
    <dc:creator>tesu</dc:creator>
    <dc:date>2013-11-18T22:17:36Z</dc:date>
    <item>
      <title>Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147789#M29281</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set with over 500 variables, and they are unordered. Currently, by using Proc Contents, I extract the ordered list of variables, copy the list from the html output, paste it onto the Excel, delete the unnecessary columns, and copy again the list. Then, I do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (paste the list of variables..)&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set mydata;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there any other method to do this with avoiding copying and pasting things? Thanks! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 22:17:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147789#M29281</guid>
      <dc:creator>tesu</dc:creator>
      <dc:date>2013-11-18T22:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147790#M29282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The general process is the same but you can automate it by using the sashelp.vcolumn list and macro variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There's a lot of posts on how to accomplish this on here so some searching should get you close to what you want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 22:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147790#M29282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-11-18T22:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147791#M29283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;proc contents data=YOURDATA out=newdataset;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=newdataset;&lt;/P&gt;&lt;P&gt;by varnum;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data newdatasetDROP;&lt;/P&gt;&lt;P&gt;set newdataset;&lt;/P&gt;&lt;P&gt;where upcase(NAME) not in ("YOUR VARIABLE NAME LIST");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sq;&lt;/P&gt;&lt;P&gt;select name into : orderedlist separated by ' '&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from newdatasetDROP;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data answer;&lt;/P&gt;&lt;P&gt;retain &amp;amp;orderedlist;&lt;/P&gt;&lt;P&gt;set YOURDATASET:&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 23:18:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147791#M29283</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-11-18T23:18:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147792#M29284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Are the variables you want or don't want following some naming pattern (eg. all unwanted variables start with 'var...')?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 23:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147792#M29284</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-18T23:54:06Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147793#M29285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Hi &lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Patrick,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;If my data looks like:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;data nordered;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt; c b a;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-size: 10pt; font-family: Courier New;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;10 555 8762&lt;/P&gt;&lt;P&gt;11 877 9748&lt;/P&gt;&lt;P&gt;12 898 2874&lt;/P&gt;&lt;P&gt;&lt;STRONG style=": ; color: #000080; font-size: 10pt; font-family: Courier New;"&gt;;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: Courier New;"&gt;Then, my data should be changed as:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Obs&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; c&lt;SPAN style="font-size: 8pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8762&amp;nbsp;&amp;nbsp;&amp;nbsp; 555&amp;nbsp;&amp;nbsp;&amp;nbsp; 10&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9748&amp;nbsp;&amp;nbsp;&amp;nbsp; 877&amp;nbsp;&amp;nbsp;&amp;nbsp; 11&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2874&amp;nbsp;&amp;nbsp;&amp;nbsp; 898&amp;nbsp;&amp;nbsp;&amp;nbsp; 12&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I don't have any other variable selection criteria. Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 00:02:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147793#M29285</guid>
      <dc:creator>tesu</dc:creator>
      <dc:date>2013-11-19T00:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147794#M29286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The issue is you haven't specified how you want them ordered. In the above example it is alphabetical, but will that always hold true?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so, then the code I gave above will work, the only difference is instead of sorting by varnum, you sort by Name. Aka the following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=YOURDATA out=newdataset;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=newdataset;&lt;/P&gt;&lt;P&gt;by NAME;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data newdatasetDROP;&lt;/P&gt;&lt;P&gt;set newdataset;&lt;/P&gt;&lt;P&gt;where upcase(NAME) not in ("YOUR VARIABLE NAME LIST");&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sq;&lt;/P&gt;&lt;P&gt;select name into : orderedlist separated by ' '&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from newdatasetDROP;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data answer;&lt;/P&gt;&lt;P&gt;retain &amp;amp;orderedlist;&lt;/P&gt;&lt;P&gt;set YOURDATASET:&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 00:16:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147794#M29286</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-11-19T00:16:48Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting (ordering) variables of a data set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147795#M29287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data nordered;&lt;BR /&gt;&amp;nbsp; input c b a;&lt;BR /&gt;&amp;nbsp; label b='just a test';&lt;BR /&gt;&amp;nbsp; cards;&lt;BR /&gt;10 555 8762&lt;BR /&gt;11 877 .&lt;BR /&gt;12 898 2874&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp; select name into :varlist separated by ' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='WORK' and memname='NORDERED'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by name&lt;BR /&gt;&amp;nbsp; ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data work.nordered;&lt;BR /&gt;&amp;nbsp; retain &amp;amp;varlist;&lt;BR /&gt;&amp;nbsp; set nordered;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc contents data=work.nordered;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Nov 2013 00:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-ordering-variables-of-a-data-set/m-p/147795#M29287</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-11-19T00:52:34Z</dc:date>
    </item>
  </channel>
</rss>

