<?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: how to rearrange the column position in sql proceure in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100012#M28072</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Or, avoid the PROC TRANSPOSE step by letting the ORDER BY clause and the KEEP= option do the work.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #ff0000;"&gt;select&lt;SPAN style="color: #000000;"&gt; name&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; into :varlist separated by &lt;SPAN style="color: #800080;"&gt;', '&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; from dictionary.columns&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; where libname EQ &lt;SPAN style="color: #800080;"&gt;'SASHELP'&lt;/SPAN&gt; and memname EQ &lt;SPAN style="color: #800080;"&gt;'ZIPCODE'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; order by name NE &lt;SPAN style="color: #800080;"&gt;'STATE'&lt;/SPAN&gt;, name NE &lt;SPAN style="color: #800080;"&gt;'CITY'&lt;/SPAN&gt;, varnum ;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #ff0000;"&gt;create&lt;/SPAN&gt; table one(keep = state city statename--dst) as&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; select &amp;amp;varlist&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&amp;nbsp; from sashelp.zipcode ;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Tom wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Here is a useful trick for getting variable lists expanded.&amp;nbsp; Use PROC TRANSPOSE to make a dataset with the variable names.&lt;/P&gt;
&lt;P&gt;You can then pull the list into a macro variable.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;proc transpose data=sashelp.zipcode(obs=0) out=_names_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var state city statename--dst ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint ;&lt;/P&gt;
&lt;P&gt;select _name_ into :varlist separated by ', ' from _names_;&lt;/P&gt;
&lt;P&gt;create table one as select &amp;amp;varlist from sashelp.zipcode ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 02 May 2012 01:55:14 GMT</pubDate>
    <dc:creator>Howles</dc:creator>
    <dc:date>2012-05-02T01:55:14Z</dc:date>
    <item>
      <title>how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/99998#M28058</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;I have a problem when I try to create a new dataset,change state and city as first and second columns and then keep column from statename to dst,but there is problem in the code:&lt;/P&gt;&lt;P&gt;please help.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;create table one as&lt;/P&gt;&lt;P&gt;select a.state&lt;/P&gt;&lt;P&gt;,a.city&lt;/P&gt;&lt;P&gt;,a.statename--a.dst&lt;/P&gt;&lt;P&gt;from sashelp.zipcode as a&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 15:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/99998#M28058</guid>
      <dc:creator>Mike_Davis</dc:creator>
      <dc:date>2012-05-01T15:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/99999#M28059</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There isn't an easy way to short cut variable selections for SQL procedures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I typically do, if I absolutely require the order is run the proc sql with a select * and the feedback option. This writes the full query to the log and then I modify that as required.&lt;/P&gt;&lt;P&gt;Saves typing but the code isn't as succinct as possible. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp; proc sql noprint &lt;STRONG&gt;feedback&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;13&lt;/P&gt;&lt;P&gt;14&amp;nbsp;&amp;nbsp; create table one as&lt;/P&gt;&lt;P&gt;15&lt;/P&gt;&lt;P&gt;16&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;17&lt;/P&gt;&lt;P&gt;18&amp;nbsp;&amp;nbsp; from sashelp.zipcode as a&lt;/P&gt;&lt;P&gt;19&lt;/P&gt;&lt;P&gt;20&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;NOTE: Statement transforms to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select A.ZIP, A.Y, A.X, A.ZIP_CLASS, A.CITY, A.STATE, A.STATECODE, A.STATENAME, A.COUNTY, A.COUNTYNM,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;A.MSA, A.AREACODE, A.AREACODES, A.TIMEZONE, A.GMTOFFSET, A.DST, A.PONAME, A.ALIAS_CITY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from SASHELP.ZIPCODE A;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: Table WORK.ONE created, with 41761 rows and 18 columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;21&lt;/P&gt;&lt;P&gt;22&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.14 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.09 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 16:52:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/99999#M28059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-05-01T16:52:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100000#M28060</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a useful trick for getting variable lists expanded.&amp;nbsp; Use PROC TRANSPOSE to make a dataset with the variable names.&lt;/P&gt;&lt;P&gt;You can then pull the list into a macro variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc transpose data=sashelp.zipcode(obs=0) out=_names_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var state city statename--dst ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt; select _name_ into :varlist separated by ', ' from _names_;&lt;/P&gt;&lt;P&gt; create table one as select &amp;amp;varlist from sashelp.zipcode ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 17:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100000#M28060</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-05-01T17:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100001#M28061</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... the '--' works as a data set option, so (no NOPRINT needed when you create a table, no table alias A needed either) ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;create table one as &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select *&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;from sashelp.zipcode (keep=state city statename--dst);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 17:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100001#M28061</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-05-01T17:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100002#M28062</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But the keep option will not change the order of the variables.&amp;nbsp; So in this case CITY ends up before STATE.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 17:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100002#M28062</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-05-01T17:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100003#M28063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;Could this be solved by using proc iml?&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 17:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100003#M28063</guid>
      <dc:creator>Mike_Davis</dc:creator>
      <dc:date>2012-05-01T17:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100004#M28064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't mind the warnings, you can use:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;create table one as &lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;select state, city, *&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;from sashelp.zipcode(keep=state city statename--dst);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;not very clean, but quick.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 17:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100004#M28064</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-05-01T17:56:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100005#M28065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... since no one else has asked, do you have to use SQL ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data one;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;retain state;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;set sashelp.zipcode (keep=state city statename--dst);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 18:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100005#M28065</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-05-01T18:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100006#M28066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Thank you Mike,&lt;/P&gt;&lt;P&gt;This is a good method while I prefer it will be in sql or IML procedure,&lt;/P&gt;&lt;P&gt;retain statement still need us list each variable which we want to rearrange.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 19:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100006#M28066</guid>
      <dc:creator>Mike_Davis</dc:creator>
      <dc:date>2012-05-01T19:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100007#M28067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your statement "retain statement still need us list each variable" is not true. You only need to list "state" and "city" in retain statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 20:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100007#M28067</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-05-01T20:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100008#M28068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi actually, you only have to list STATE (I edited my posting !!!).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 20:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100008#M28068</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-05-01T20:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100009#M28069</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry for I didn't express my opinon clearly,I have revised it:&lt;/P&gt;&lt;P&gt;retain statement still need us list each variable &lt;STRONG style="text-decoration: underline;"&gt;which we want to rearrange&lt;/STRONG&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 20:28:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100009#M28069</guid>
      <dc:creator>Mike_Davis</dc:creator>
      <dc:date>2012-05-01T20:28:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100010#M28070</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;Mike.Davis wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Sorry for I didn't express my opinon clearly,I have revised it:&lt;/P&gt;
&lt;P&gt;retain statement still need us list each variable &lt;SPAN style="text-decoration: underline;"&gt;&lt;STRONG&gt;which we want to rearrange&lt;/STRONG&gt;&lt;/SPAN&gt;.&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt;How can you rearrange the variables without referring to them?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 01 May 2012 20:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100010#M28070</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-05-01T20:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100011#M28071</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;like use:&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;select 5th_variable--20th_variable, 2nd_variable&lt;/P&gt;&lt;P&gt;from..&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 00:07:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100011#M28071</guid>
      <dc:creator>Mike_Davis</dc:creator>
      <dc:date>2012-05-02T00:07:09Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100012#M28072</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Or, avoid the PROC TRANSPOSE step by letting the ORDER BY clause and the KEEP= option do the work.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px; color: #ff0000;"&gt;select&lt;SPAN style="color: #000000;"&gt; name&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; into :varlist separated by &lt;SPAN style="color: #800080;"&gt;', '&lt;/SPAN&gt; &lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; from dictionary.columns&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; where libname EQ &lt;SPAN style="color: #800080;"&gt;'SASHELP'&lt;/SPAN&gt; and memname EQ &lt;SPAN style="color: #800080;"&gt;'ZIPCODE'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; order by name NE &lt;SPAN style="color: #800080;"&gt;'STATE'&lt;/SPAN&gt;, name NE &lt;SPAN style="color: #800080;"&gt;'CITY'&lt;/SPAN&gt;, varnum ;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&lt;SPAN style="color: #ff0000;"&gt;create&lt;/SPAN&gt; table one(keep = state city statename--dst) as&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt; select &amp;amp;varlist&lt;/P&gt;
&lt;P style="margin: 0.0px 0.0px 0.0px 0.0px;"&gt;&amp;nbsp; from sashelp.zipcode ;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Tom wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Here is a useful trick for getting variable lists expanded.&amp;nbsp; Use PROC TRANSPOSE to make a dataset with the variable names.&lt;/P&gt;
&lt;P&gt;You can then pull the list into a macro variable.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;proc transpose data=sashelp.zipcode(obs=0) out=_names_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; var state city statename--dst ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint ;&lt;/P&gt;
&lt;P&gt;select _name_ into :varlist separated by ', ' from _names_;&lt;/P&gt;
&lt;P&gt;create table one as select &amp;amp;varlist from sashelp.zipcode ;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 01:55:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100012#M28072</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-05-02T01:55:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to rearrange the column position in sql proceure</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100013#M28073</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So did you try the method proposed by Howels ? I like it.&lt;/P&gt;&lt;P&gt;Querying dictionary can get whatever order you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 05:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/how-to-rearrange-the-column-position-in-sql-proceure/m-p/100013#M28073</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-05-02T05:02:52Z</dc:date>
    </item>
  </channel>
</rss>

