<?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: Use RETAIN to re-order variables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127748#M34934</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't use RETAIN just to reorder the variables.&amp;nbsp; Use ATTRIB, LENGTH, or even FORMAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RETAIN has a significant side effect here in that the input data buffer is not cleared between observations.&amp;nbsp; It is valuable when used as designed, but can be nasty when doing SETs with different variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc Muhlbaier&lt;/P&gt;&lt;P&gt;Duke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Sep 2012 15:59:37 GMT</pubDate>
    <dc:creator>Doc_Duke</dc:creator>
    <dc:date>2012-09-21T15:59:37Z</dc:date>
    <item>
      <title>Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127747#M34933</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;I’ve a question about using RETAIN to reorder the variable order in a dataset. I know I can use retain, such as the following&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATA want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain Var3 Var4 Var2 Var1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;(I also just learned I could us attrib to do it, such as the following)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; D&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN class="kw6"&gt;ATA&lt;/SPAN&gt;&amp;nbsp;&amp;nbsp; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN class="kw4"&gt;ttrib&lt;/SPAN&gt; Var3 Var4 Var2 Var1;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;set old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;But I also know from my experience that I could mess up the output data if I’ve data processing work after the SET statement. I don't exactly remember the kind of data processing I used when I noticed the problem. Now that I'm using RETAIN a lot to reorder the variables, I thought I'd better know what kind of the data processing after SET will mess up or won’t mess up the data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;Say instead of the two steps below,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; combined; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;merge&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; data1 data2; &lt;/SPAN&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; id; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; combined; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; var3 var4 var1 var2; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; combined; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;Can I do in one step without causing any problem?&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; combined; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; var3 var4 var1 var2; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;merge&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; data1 data2; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; id; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; text-indent: 0.5in;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;How about it's more than just merging but involve creating derived variables, processing missing values, say the following? &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;new; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;retain&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;var3 var4 var1 var2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;SPAN style="color: blue; background: none repeat scroll 0% 0% white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="color: black; background: none repeat scroll 0% 0% white;"&gt; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;old;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If var3=. then var3=var2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; font-size: 10pt;"&gt;&lt;STRONG style="color: navy; background: none repeat scroll 0% 0% white;"&gt;run&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial,helvetica,sans-serif; color: black; background: none repeat scroll 0% 0% white; font-size: 10pt;"&gt;Sorry I can't find an example when I noticed the problem of using RETAIN. Any general comments about potential problems when using retain are appreciated.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 15:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127747#M34933</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-21T15:54:39Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127748#M34934</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Don't use RETAIN just to reorder the variables.&amp;nbsp; Use ATTRIB, LENGTH, or even FORMAT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;RETAIN has a significant side effect here in that the input data buffer is not cleared between observations.&amp;nbsp; It is valuable when used as designed, but can be nasty when doing SETs with different variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Doc Muhlbaier&lt;/P&gt;&lt;P&gt;Duke&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 15:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127748#M34934</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2012-09-21T15:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127749#M34935</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I learned the issues about RETAIN much later on.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But with ATTRIB, LENGTH, FORMAT, it's quite inconvenient to use them because I have to specify the format or length of each of the variables involved, such as the following. Is there an easy way out?&lt;/P&gt;&lt;P&gt;data attrib_method; attrib a b c d format=1.; set sample;&lt;/P&gt;&lt;P&gt;data attrib_method;attrib a b c d informat=1.;set sample;&lt;/P&gt;&lt;P&gt;data attrib_method;attrib a b c d label=’example’; set sample;&lt;/P&gt;&lt;P&gt;data attrib_method; attrib a b c d length=3.; set sample;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 16:41:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127749#M34935</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-21T16:41:36Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127750#M34936</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Retain is fine as long as you know what it does and does NOT do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For variables coming from SET MERGE or UPDATE is does nothing except to change the order when the RETAIN statement is placed properly.&amp;nbsp; Variables coming from SET MERGE or UPDATE are NOT initialized to missing like variables that are created in a data step or read from INFILE.&amp;nbsp; That's why something like "if _N_ eq 1 then set ...;"&amp;nbsp; works to put the values read from this SET statement on every observation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you use RETAIN on variables that ARE created in a data step then you will need to understand the effect that will have on those variables and "program" accordinly.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 17:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127750#M34936</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-09-21T17:12:20Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127751#M34937</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could also use a KEEP statement, but then you have to specify EVERY variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 19:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127751#M34937</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2012-09-21T19:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127752#M34938</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't believe KEEP will work to reorder variables.&amp;nbsp; Can you make example?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 20:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127752#M34938</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-09-21T20:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127753#M34939</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think KEEP works (unless there are tricks in specifying it). I guess it's a trade off for using RETAIN. Do I mind the data processing time for using RETAIN just for reordering variable? Do I want to spend time specifying the format/length of each of the variables involved in reordering when using attrib, length, format, etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Sep 2012 22:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127753#M34939</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2012-09-21T22:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127754#M34940</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can use the KEEP and/or DROP dataset option.&lt;/P&gt;&lt;P&gt;One way to get variables defined is to copy the definition from an existing dataset.&amp;nbsp; You can use a SET statement that is not executed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: arial, helvetica, sans-serif; color: #000000;"&gt;&lt;SPAN style="font-style: inherit; font-family: inherit; background-color: white; background-position: 0% 0%;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-style: inherit; font-family: inherit; background-color: white; background-position: 0% 0%;"&gt; combined;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;&amp;nbsp; if 0 then set data2 (keep=&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;var3 var4) data1(keep= var1 var2);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;&amp;nbsp; merge&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt; data1 data2;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;&amp;nbsp; by&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt; id;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="color: #000000;"&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;run&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit; font-size: 10pt; font-style: inherit; text-indent: 0.5in; background-color: white; background-position: 0% 0%;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Sep 2012 02:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127754#M34940</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-09-22T02:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127755#M34941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While I usually agree with Tom, and he's a heck of a lot smarter than me ;-), on this occasion I'll disagree.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;IMO, the keep statement will set the variable &lt;SPAN style="text-decoration: underline;"&gt;attributes&lt;/SPAN&gt;, but doesn't give you much, if any, control over the variable &lt;SPAN style="text-decoration: underline;"&gt;order&lt;/SPAN&gt; in the PDV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example, if in data2, the (kept) variables are in this order:&amp;nbsp; var4 var3, and in data1 the variables are in this order:&amp;nbsp; var2 var1, then in the final dataset the variable order would be var4 var3 var2 var1 (then all the other variables contributed by data1 and data2 on the merge statement), NOT the order you'd think from the keep statement.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Plus, as stated above, any variables that are defined via a set or merge statement have an implied retain, which has occasionally bit me in the past.&amp;nbsp; That's also why you'll see "if 0 then set somedataset (keep=whatever)" to set the variable &lt;SPAN style="text-decoration: underline;"&gt;attributes&lt;/SPAN&gt; when using a data step hash object, &lt;SPAN style="text-decoration: underline;"&gt;but with call missing somewhere in the mix&lt;/SPAN&gt; (often call missing (of _all_) to code around the implied retain issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I digress...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My favourite approach when I want to reorder the variables in the PDV is a "naked format" statement.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data whatever;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format height weight age sex name;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;During data step compilation, the compiler will set the variable PDV order based on the order of the statements in the data step.&amp;nbsp; In this example, the variable order is set by the format statement.&amp;nbsp; Then, the set statement kicks in, defining the rest of the variable attributes (length, label, format, informat).&amp;nbsp; If the variables have a permanent format associated with them in the dataset, "last one wins", and the format is associated with the variable at that point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Occasionally this approach doesn't work, for example if I need to reference a variable before the set statement.&amp;nbsp; Since the variable attributes aren't set by the format statement, and numeric variables are the default, occasionally I get a character variable cast as numeric.&amp;nbsp; In this scenario, I need to revert to a length statement.&amp;nbsp; But this is rare.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a first approach, try the "naked format" statement, and see if that works for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;HTH...&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Sep 2012 07:03:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127755#M34941</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2012-09-22T07:03:23Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127756#M34942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That's no different from RETAIN (not as good actually) and you could end up needing a set statement for every variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Sep 2012 13:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127756#M34942</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-09-22T13:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127757#M34943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't want to "move" them around after the fact create the variables in the proper order to begin with.&amp;nbsp; I showed you how to get TRANSPOSE to do that in your TRANSPOSE thread.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Sep 2012 13:33:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127757#M34943</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2012-09-22T13:33:11Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127758#M34944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Too bad that a "naked" ATTRIBUTE statement is not allowed.&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Scott Bass wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;[snip]&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;My favourite approach when I want to reorder the variables in the PDV is a "naked format" statement.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;data whatever;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; format height weight age sex name;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set sashelp.class;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;During data step compilation, the compiler will set the variable PDV order based on the order of the statements in the data step.&amp;nbsp; In this example, the variable order is set by the format statement.&amp;nbsp; Then, the set statement kicks in, defining the rest of the variable attributes (length, label, format, informat).&amp;nbsp; If the variables have a permanent format associated with them in the dataset, "last one wins", and the format is associated with the variable at that point.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Occasionally this approach doesn't work, for example if I need to reference a variable before the set statement.&amp;nbsp; Since the variable attributes aren't set by the format statement, and numeric variables are the default, occasionally I get a character variable cast as numeric.&amp;nbsp; In this scenario, I need to revert to a length statement.&amp;nbsp; But this is rare.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;As a first approach, try the "naked format" statement, and see if that works for you.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;HTH...&lt;/P&gt;
&lt;P&gt;Scott&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Sep 2012 16:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/127758#M34944</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-09-22T16:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/319611#M61902</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's Note: This is a popular topic.&amp;nbsp; The following SAS Note shows how to reorder variables in a SAS data set:&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/kb/8/395.html" target="_blank"&gt;Usage Note 8395&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 18:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/319611#M61902</guid>
      <dc:creator>kmw</dc:creator>
      <dc:date>2016-12-16T18:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Use RETAIN to re-order variables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/399695#M66661</link>
      <description>&lt;P&gt;From the usage note:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;For example, there are six variables in data set ONE in the positional order of A, B, C, D, E, and F. If the new order needs to be A, E, C, D, B, and F, then the following DATA step reorders the variables in that order:&lt;/P&gt;&lt;DIV class="indent1"&gt;&lt;PRE&gt;data two;
   retain a e c d b;
   set one;
run;&lt;/PRE&gt;&lt;/DIV&gt;&lt;P&gt;As noted, the variable F is left off the RETAIN statement since the order of variable F should not change. After running the above DATA step, the variables in data set ONE are in the order of A, E, C, D, B and F.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So expanding on the Usage Note:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
   set sashelp.class;
   a=name;
   b=age;
   c=sex;
   d=weight;
   e=height;
   f=height*weight;
   keep a--f;
run;

data two;
   retain g a e c d b;
   set one;
   if c='M' then g='FOO';
run;

data three;
   format g a e c d b;
   set one;
   if c='M' then g='FOO';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Compare the output between two and three. &amp;nbsp;IMO the output from two is possibly undesired, and the output from three is as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The usage note is good, but IMO should go into more detail of the repercussions of using retain to set the PDV order for a data step (as opposed to data set) variable. &amp;nbsp;Obviously an experienced SAS programmer would know this, but this could catch a newbie.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 03:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Use-RETAIN-to-re-order-variables/m-p/399695#M66661</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2017-09-29T03:57:03Z</dc:date>
    </item>
  </channel>
</rss>

