<?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 can I re-order variables in a dataset in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32351#M7784</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;using retain statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; sashelp.class (obs=&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; height weight age name sex;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 18 Jan 2012 15:57:14 GMT</pubDate>
    <dc:creator>Linlin</dc:creator>
    <dc:date>2012-01-18T15:57:14Z</dc:date>
    <item>
      <title>How can I re-order variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32349#M7782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Any idea how I can reorder variables in a dataset?&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jan 2012 15:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32349#M7782</guid>
      <dc:creator>bncoxuk</dc:creator>
      <dc:date>2012-01-18T15:52:00Z</dc:date>
    </item>
    <item>
      <title>How can I re-order variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32350#M7783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use a retain statement but place it before the set statement.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; retain name height weight age;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jan 2012 15:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32350#M7783</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-01-18T15:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How can I re-order variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32351#M7784</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;using retain statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; sashelp.class (obs=&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; height weight age name sex;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; class;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt;;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 18 Jan 2012 15:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32351#M7784</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-01-18T15:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: How can I re-order variables in a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32352#M7785</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;pardon me for butting in &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to suggest a significant change to this "standard" re-ordering.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rather than re-create the data in the order required (this time?) create a &lt;STRONG&gt;VIEW&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then only when columns are being read will that data be rearranged. &lt;/P&gt;&lt;P&gt;(and it probably makes no difference to the performance of reading the data)&lt;/P&gt;&lt;P&gt;OK a view might require a little storage, but probably very very little.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once the concept is accepted, a few advantages become apparent!&lt;/P&gt;&lt;P&gt;&lt;A&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For a substantial (or even BIG) data set - expect &lt;STRONG&gt;to make more than one re-arrangement&lt;/STRONG&gt; - it's only another VIEW! &lt;/P&gt;&lt;P&gt;Create VIEWS for every new order requested.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Obviously the VIEW process will vary only in the order required and the name of the VIEW to be created. So that suggests a macro. Perhaps it might be as simple as your code wrapped in a macro like:&lt;/P&gt;&lt;P&gt;%macro new_view( data= input_table, VIEW= new_VIEW, columns= a b c ) ;&lt;/P&gt;&lt;P&gt;data &amp;amp;VIEW / view= &amp;amp;VIEW ; &lt;/P&gt;&lt;P&gt;retain &amp;amp;columns ;&lt;/P&gt;&lt;P&gt;set &amp;amp;data ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;%mend ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;but you know me ... &lt;/P&gt;&lt;P&gt;for a basic capability, I expect it to be reused many times until, it is used by those who might not understand it so well. Preparing for that, I add checks that the input exists, and can be opened, and the output is not already in existence (unless the caller adds a parameter to confirm "replace") so I tested the macro %new_view, attached as the file new_view.sas&lt;/P&gt;&lt;P&gt;Usage&lt;/P&gt;&lt;P&gt;%new_view( data= sashelp.vformat, view= sasuser.vformat, columns fmtName fmtType minw defw maxw mind defd maxd );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;regards&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jan 2012 11:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-re-order-variables-in-a-dataset/m-p/32352#M7785</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2012-01-19T11:17:37Z</dc:date>
    </item>
  </channel>
</rss>

