<?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 variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102324#M21410</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="3068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; agreed!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Oct 2012 00:28:57 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2012-10-22T00:28:57Z</dc:date>
    <item>
      <title>Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102312#M21398</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello Everyone&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a process which runs monthly and creates dataset with variables X1 , X2, X3 and so on. The number of variables changes like X1 X2 X3 X4........ X10 . Before running the program , I don't know how many variables will generate but it generates in series X(num). The problem is in the output Variables are&amp;nbsp; not coming in the right order. They are scrambled like X2 X4 X1 X3. I want to have the result like X1 X2 X3 X4 and so on.&lt;/P&gt;&lt;P&gt;I tried using Retain statment with&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data ... ;&lt;/P&gt;&lt;P&gt;Retain Obs_num X1- X: ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But this did not work.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 13:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102312#M21398</guid>
      <dc:creator>bnarang</dc:creator>
      <dc:date>2012-10-20T13:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102313#M21399</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input x1 x3 x5 x2 x4 obs_num;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 3 5 2 4 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%let lib=work;&lt;/P&gt;&lt;P&gt;%let dsn=have;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :names separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.vcolumn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="%upcase(&amp;amp;lib)" and memname="%upcase(&amp;amp;dsn)"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by name;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain &amp;amp;names;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;lib..&amp;amp;dsn;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Obs&amp;nbsp;&amp;nbsp;&amp;nbsp; obs_num&amp;nbsp;&amp;nbsp;&amp;nbsp; x1&amp;nbsp;&amp;nbsp;&amp;nbsp; x2&amp;nbsp;&amp;nbsp;&amp;nbsp; x3&amp;nbsp;&amp;nbsp;&amp;nbsp; x4&amp;nbsp;&amp;nbsp;&amp;nbsp; x5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 13:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102313#M21399</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-20T13:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102314#M21400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a quick and dirty (but OK) approach to get you going.&amp;nbsp; You do not need to know how many columns.&amp;nbsp; Transpose 1 row of data from a Nx2 wide to a 2xN table containing _NAME_ (names of original columns) and Col1 the transposed data.&amp;nbsp; Sort by _NAME_; then transpose back again.&amp;nbsp; Use the re-ordered columns as a template for your output data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Transpose&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data = ProcessData (obs = 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Out&amp;nbsp;&amp;nbsp; = Varnames&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Var&amp;nbsp; _ALL_ ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Sort&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data = Varnames ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; By&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; _NAME_ ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc Transpose&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Data = Varnames&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Out&amp;nbsp;&amp;nbsp; = Varcols (Drop = _NAME_)&amp;nbsp; /*Also drop _LABEL_ if your process data has labels*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data ProcessData ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Length ObsNum 8 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set Varcols (obs = 0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ProcessData&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the total number of rows output by your process is small (&amp;lt; ~1000) you can transpose the whole table, sort it, and transpose back.&lt;/P&gt;&lt;P&gt;NB this method assumes you do not have a mix of character and numeric data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 13:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102314#M21400</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2012-10-20T13:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102315#M21401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You will run into a problem using proc sql unless you first account for the numeric collation issue regarding x10 (i.e., I presume that you don't want x1 x10 x2 x3, etc.).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you can live with some irrelevant notes the easiest solution is simply:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain x1-x10;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you can't accept notes, as such, an alternative might be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table names as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="WORK" and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; memname="HAVE" and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name like "x%"&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data names;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set names;&lt;/P&gt;&lt;P&gt;&amp;nbsp; key_num=sortkey(name,,,,'N');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :names&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; separated by " "&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from names&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by key_num&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain &amp;amp;names.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 14:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102315#M21401</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-20T14:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102316#M21402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PROC CONTENTS will produce the correct order for the enumearated variabls.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; x1 x10 x3 x5 x2 x4 obs_num;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: #ffffc0; color: black; font-family: 'Courier New';"&gt;1 3 5 2 4 1 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;;;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;contents&lt;/STRONG&gt; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;noprint&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;=vars(keep=name);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;noprint&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; name &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;into&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; :vars separated &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;by&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; background: white; color: purple; font-family: 'Courier New';"&gt;' '&lt;/SPAN&gt; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;from&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; vars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; need;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; &amp;amp;vars;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10pt; background: white; color: blue; font-family: 'Courier New';"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG style="color: navy; background: white; font-size: 10pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 15:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102316#M21402</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-10-20T15:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102317#M21403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="27540" __jive_macro_name="message" class="jive_macro jive_macro_message" data-objecttype="2" href="https://communities.sas.com/"&gt;&lt;/A&gt; : I didn't know that!&amp;nbsp; Definitely easier for the OP's purpose.&amp;nbsp; Interestingly, it doesn't work as expected if their are some extra variables in the list (like 9a, 9b, 10a and 10b) where the use of the sortkey function does produce the correct(?) order (e.g., will result with x1, x2, x3, x3a, x3b, x4, etc.).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 16:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102317#M21403</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-20T16:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102318#M21404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about the modified one:&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input x1 x3 x10 x5 x2 x4 x9 x8 x7 x6 obs_num;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 3 5 10 2 4 9 8 7 6 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%let lib=work;&lt;/P&gt;&lt;P&gt;%let dsn=have;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :names separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.vcolumn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="%upcase(&amp;amp;lib)" and memname="%upcase(&amp;amp;dsn)" and&amp;nbsp; name like "x%"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by put(input(compress(name,,'a'),3.),z3.);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;names;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain obs_num &amp;amp;names;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;lib..&amp;amp;dsn;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 16:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102318#M21404</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-20T16:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102319#M21405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a nice, straightforward explanation-by-example of how to re-order variables in SAS.&lt;/P&gt;&lt;P&gt;&lt;A href="http://analytics.ncsu.edu/sesug/2002/PS12.pdf" title="http://analytics.ncsu.edu/sesug/2002/PS12.pdf"&gt;http://analytics.ncsu.edu/sesug/2002/PS12.pdf&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 17:35:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102319#M21405</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2012-10-20T17:35:55Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102320#M21406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, what is "correct"?&amp;nbsp; SORKEY is good but how do you get it to work in SQL. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;x9a would not be consided a variable in an enumerated list like x1-x10.&amp;nbsp; It depends on what you want I reckon.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 19:11:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102320#M21406</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-10-20T19:11:28Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102321#M21407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="3068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; : Works for me!&amp;nbsp; Nice addition!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 20 Oct 2012 20:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102321#M21407</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-20T20:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102322#M21408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everyone. I have got quite a options to solve the problem. It' s very difficult to choose the correct Answer since all of them are correct.(or we have choice to select multiple correct?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks a lot.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Oct 2012 03:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102322#M21408</guid>
      <dc:creator>bnarang</dc:creator>
      <dc:date>2012-10-21T03:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102323#M21409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your encouragement!&amp;nbsp; The updated code also orders &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;extra variables in the list (like 9a, 9b, 10a and 10b):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input x1 x3b x3 x3a x10 x5 x2 x4 x9 x3d x8 x7 x6 obs_num;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1 32 3 31 10 5 2 4 9 34 8 7 6 1&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;%let lib=work;&lt;/P&gt;&lt;P&gt;%let dsn=have;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select name into :names separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.vcolumn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname="%upcase(&amp;amp;lib)" and memname="%upcase(&amp;amp;dsn)" and&amp;nbsp; name like "x%"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by put(input(compress(name,,'a'),3.),z3.) ,substr(name,length(name));&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;names;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain obs_num &amp;amp;names;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set &amp;amp;lib..&amp;amp;dsn;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 00:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102323#M21409</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-10-22T00:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102324#M21410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="3068" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; agreed!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 00:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102324#M21410</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-10-22T00:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Reordering variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102325#M21411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's another one, and an old trick that I use...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't mind about notes AND the variable labels, use the ATTRIB statement &lt;SPAN style="text-decoration: underline;"&gt;before&lt;/SPAN&gt; the SET, to force the reordering of the columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;"&gt;attrib x1-x10 label='';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;"&gt;set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: navy;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;More on the ATTRIB statement here:&lt;/P&gt;&lt;P&gt;&lt;A class="active_link" href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000179227.htm" title="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000179227.htm"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000179227.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers from Portugal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Oct 2012 09:10:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reordering-variables/m-p/102325#M21411</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2012-10-22T09:10:15Z</dc:date>
    </item>
  </channel>
</rss>

