<?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: To change the order of  variables(columns) in a SAS-table. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10639#M882</link>
    <description>As others have observed on this forum, the RETAIN statement should be avoided, unless absolutely necessary.  Search the archives for additional comments / discussion on the particular point.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Mon, 02 Nov 2009 16:02:25 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-11-02T16:02:25Z</dc:date>
    <item>
      <title>To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10632#M875</link>
      <description>My table has variables ID, A, B and C, in that order. I assign the sum of A, B and C to the variable SUM.&lt;BR /&gt;
&lt;BR /&gt;
The order of the variables in my table then is ID, A, B, C, SUM.&lt;BR /&gt;
&lt;BR /&gt;
For some reason I want the order to be: ID, B, C, A, SUM.&lt;BR /&gt;
&lt;BR /&gt;
How can that be coded?</description>
      <pubDate>Mon, 02 Nov 2009 08:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10632#M875</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-02T08:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10633#M876</link>
      <description>Thera are many ways to do this, but the easiest must be:&lt;BR /&gt;
&lt;BR /&gt;
data out;&lt;BR /&gt;
 keep ID B C A SUM;&lt;BR /&gt;
 set in;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 02 Nov 2009 09:08:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10633#M876</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2009-11-02T09:08:28Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10634#M877</link>
      <description>Yep another way would be to use proc sql with the select statement.&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
create table new_tab from&lt;BR /&gt;
select ID,B,C,A,SUM from tab;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Whatever method you will use, it always implies recreating the table with a new structure.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 02 Nov 2009 10:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10634#M877</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-11-02T10:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10635#M878</link>
      <description>I dont understand why this will work, when I try&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
  keep age name ;&lt;BR /&gt;
  set sashelp.class;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I get name before age?&lt;BR /&gt;
&lt;BR /&gt;
The only way I can get this to work is either by using proc SQL or by using the attrib (or format/lenght) in the datastep.</description>
      <pubDate>Mon, 02 Nov 2009 12:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10635#M878</guid>
      <dc:creator>GertNissen</dc:creator>
      <dc:date>2009-11-02T12:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10636#M879</link>
      <description>You're right Geniz.&lt;BR /&gt;
&lt;BR /&gt;
Keep wouldn't do the trick, since it just filters columns names into the dataset without changing the actual position.&lt;BR /&gt;
&lt;BR /&gt;
Only SQL, ATTRIB or LENGTH statements will reorder the position of columns into a new dataset.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Mon, 02 Nov 2009 12:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10636#M879</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-11-02T12:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10637#M880</link>
      <description>Why is it important to influence the SAS-internal variable order anyway?  What are you attempting to accomplish by doing so?&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 02 Nov 2009 13:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10637#M880</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-02T13:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10638#M881</link>
      <description>I was a bit too quick, the right code should be:&lt;BR /&gt;
&lt;BR /&gt;
data out;&lt;BR /&gt;
retain ID B C A SUM;&lt;BR /&gt;
set in;&lt;BR /&gt;
run;</description>
      <pubDate>Mon, 02 Nov 2009 15:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10638#M881</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2009-11-02T15:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10639#M882</link>
      <description>As others have observed on this forum, the RETAIN statement should be avoided, unless absolutely necessary.  Search the archives for additional comments / discussion on the particular point.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 02 Nov 2009 16:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10639#M882</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-02T16:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10640#M883</link>
      <description>There you go again.  What is your problem with RETAIN?  So, you wrote a program once upon a time that didn't work because you don't understand RETAIN and now you have a vendetta against the poor defenseless RETAIN statement.  I’m sorry but the statement “RETAIN should be avoided” sounds ridiculous to me.&lt;BR /&gt;
&lt;BR /&gt;
What other SAS statements or procedures do you avoid?</description>
      <pubDate>Mon, 02 Nov 2009 18:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10640#M883</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-11-02T18:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10641#M884</link>
      <description>Scan the forum archives - we've been down this path before, but not again.  &lt;BR /&gt;
&lt;BR /&gt;
No question that there are very specific opportunities to use a RETAIN statement, mostly to iterate a DATA step maintaining a "unique named" SAS variable across a step RETURN/DELETE, either explicit or implicit.&lt;BR /&gt;
&lt;BR /&gt;
If you choose, enjoy using the RETAIN statement to your heart's content.  &lt;BR /&gt;
&lt;BR /&gt;
To do so, unless the need calls for it, is an opportunity for problems with SAS application program maintenance -- obviously my personal opinion.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 02 Nov 2009 19:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10641#M884</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-11-02T19:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10642#M885</link>
      <description>The table should be exported to Excel.&lt;BR /&gt;
&lt;BR /&gt;
It should be done directly, in one process, by running the SAS-code, so I am using DDE.&lt;BR /&gt;
&lt;BR /&gt;
The order of the variables in the original SAS-table is given, and the order in the Excel worksheet is decided to be another.&lt;BR /&gt;
&lt;BR /&gt;
In the real situation there are many more variables than in my initial example.&lt;BR /&gt;
&lt;BR /&gt;
Thanks to everyone for your commitment.</description>
      <pubDate>Mon, 02 Nov 2009 20:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10642#M885</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-11-02T20:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10643#M886</link>
      <description>ErnestoC&lt;BR /&gt;
 &lt;BR /&gt;
as you write to excel with dde, you can specify the columns in your chosen order,&lt;BR /&gt;
 &lt;BR /&gt;
 at that stage (in the data step which writes).&lt;BR /&gt;
 &lt;BR /&gt;
If you chose to write to a new workbook with for example tagsets.excelxp, you could define the required column order in the VAR statement of proc print  &lt;BR /&gt;
 &lt;BR /&gt;
Neither method would need the "input data set" to have a specific column order.&lt;BR /&gt;
&lt;BR /&gt;
Why try harder?&lt;BR /&gt;
  &lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 03 Nov 2009 09:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10643#M886</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-11-03T09:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: To change the order of  variables(columns) in a SAS-table.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10644#M887</link>
      <description>Hi Scott&lt;BR /&gt;
 &lt;BR /&gt;
I understand you have some resistance to RETAIN&lt;BR /&gt;
 &lt;BR /&gt;
were you aware that most variables read into a data step will naturally (and unavoidably) RETAIN? &lt;BR /&gt;
 &lt;BR /&gt;
That excludes only new columns derived in a step (created via assignment or input).&lt;BR /&gt;
(but it does not exclude variables which are named on statement options, like filevar= and in= ) &lt;BR /&gt;
 &lt;BR /&gt;
So a proper understanding of RETAIN is possibly (or probably) an "essential" for SAS training. (imho)&lt;BR /&gt;
 &lt;BR /&gt;
Given that proper understanding (and respect), I see no reason to propose avoiding the RETAIN statement as a sensible technique for arranging column order. &lt;BR /&gt;
(I have probably learned a lot from tripping up over my mistakes, like non-use of RETAIN).&lt;BR /&gt;
.... just my $0.02  &lt;BR /&gt;
 &lt;BR /&gt;
kind regards&lt;BR /&gt;
PeterC</description>
      <pubDate>Tue, 03 Nov 2009 09:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-change-the-order-of-variables-columns-in-a-SAS-table/m-p/10644#M887</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-11-03T09:32:10Z</dc:date>
    </item>
  </channel>
</rss>

