<?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 variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76282#M16501</link>
    <description>A SAS variable referred to on a RETAIN statement has its value maintained across DATA step passes, so it's value must either be contributed with a SET input (or other DATA step input / load) processing or explicitly when assigned a value outright in a DATA step, in all cases.  This is counter to traditional SAS DATA step processing where SAS variables are reset to missing/blank value with each DATA step pass.  The position of a RETAIN, when used for variable ordering also influences a SAS DATA step, specifically a RETAIN before a SET operates differently than a RETAIN after a SET.  I see no issue with using RETAIN for work variables or those SAS data step variables passed from macro variables, but it's when a SAS assignment statement (intended for output) must be addressed in all cases is what is concerning to me, due to possibility of lingering values from prior passes.&lt;BR /&gt;
&lt;BR /&gt;
As mentioned - if it can be avoided.  Clearly a RETAIN'd variable has its place in a DATA step, when used appropriately.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Mon, 09 Mar 2009 21:40:30 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-03-09T21:40:30Z</dc:date>
    <item>
      <title>How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76275#M16494</link>
      <description>I am merging two datasets but the output dataset has my variables all over the place.  I have a keep statement with the order of the variables why doesn't that keep that order?&lt;BR /&gt;
&lt;BR /&gt;
What is the best way to have my data sets have the correct order I want? &lt;BR /&gt;
&lt;BR /&gt;
In this case I have about 20-30 variables that I want in a specific order.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you for any help</description>
      <pubDate>Wed, 04 Mar 2009 15:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76275#M16494</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-04T15:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76276#M16495</link>
      <description>As I just learnt from data _null_...&lt;BR /&gt;
&lt;BR /&gt;
Use retain before set to order your variables, seemes to be the easiest (and best?) way:&lt;BR /&gt;
&lt;BR /&gt;
data output;&lt;BR /&gt;
 retain a b c d;&lt;BR /&gt;
 set input;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 04 Mar 2009 15:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76276#M16495</guid>
      <dc:creator>FredrikE</dc:creator>
      <dc:date>2009-03-04T15:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76277#M16496</link>
      <description>FredrikE,&lt;BR /&gt;
&lt;BR /&gt;
That was it.  &lt;BR /&gt;
&lt;BR /&gt;
Thank you so much&lt;BR /&gt;
&lt;BR /&gt;
Jerry</description>
      <pubDate>Wed, 04 Mar 2009 16:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76277#M16496</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-04T16:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76279#M16498</link>
      <description>Please provide and example of &lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; SAS would retain values inside the SAS datastep ( Might through some suprises)</description>
      <pubDate>Mon, 09 Mar 2009 19:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76279#M16498</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-09T19:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76280#M16499</link>
      <description>Using a RETAIN statement at all, unless absolutely necessary, is a dangerous technique altogether, in my opinion.  So, if you must have some variable order, for whatever purpose, attempt to address the requirement on the output side, if that is a PROC PRINT, CSV, or otherwise.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 09 Mar 2009 20:32:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76280#M16499</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-09T20:32:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76281#M16500</link>
      <description>&amp;gt; Using a RETAIN statement at all, unless absolutely&lt;BR /&gt;
&amp;gt; necessary, is a dangerous technique altogether, in my&lt;BR /&gt;
&amp;gt; opinion.  &lt;BR /&gt;
&lt;BR /&gt;
I don't understand your statement.  How is RETAIN dangerous?  The function of the statement is clearly documented.   You are the second person to warn of a danger with RETAIN but provide no example.  Surely if there is a problem we would all like to see it.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; So, if you must have some variable order,&lt;BR /&gt;
&amp;gt; for whatever purpose, attempt to address the&lt;BR /&gt;
&amp;gt; requirement on the output side, if that is a PROC&lt;BR /&gt;
&amp;gt; PRINT, CSV, or otherwise.&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Scott Barry&lt;BR /&gt;
&amp;gt; SBBWorks, Inc.</description>
      <pubDate>Mon, 09 Mar 2009 21:11:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76281#M16500</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-09T21:11:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76282#M16501</link>
      <description>A SAS variable referred to on a RETAIN statement has its value maintained across DATA step passes, so it's value must either be contributed with a SET input (or other DATA step input / load) processing or explicitly when assigned a value outright in a DATA step, in all cases.  This is counter to traditional SAS DATA step processing where SAS variables are reset to missing/blank value with each DATA step pass.  The position of a RETAIN, when used for variable ordering also influences a SAS DATA step, specifically a RETAIN before a SET operates differently than a RETAIN after a SET.  I see no issue with using RETAIN for work variables or those SAS data step variables passed from macro variables, but it's when a SAS assignment statement (intended for output) must be addressed in all cases is what is concerning to me, due to possibility of lingering values from prior passes.&lt;BR /&gt;
&lt;BR /&gt;
As mentioned - if it can be avoided.  Clearly a RETAIN'd variable has its place in a DATA step, when used appropriately.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 09 Mar 2009 21:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76282#M16501</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-09T21:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76283#M16502</link>
      <description>&amp;gt; A SAS variable referred to on a RETAIN statement has&lt;BR /&gt;
&amp;gt; its value maintained across DATA step passes, so it's&lt;BR /&gt;
&amp;gt; value must either be contributed with a SET input (or&lt;BR /&gt;
&amp;gt; other DATA step input / load) processing or&lt;BR /&gt;
&amp;gt; explicitly when assigned a value outright in a DATA&lt;BR /&gt;
&amp;gt; step, in all cases.  &lt;BR /&gt;
&lt;BR /&gt;
I don't understand what you are getting at.  &lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; This is counter to traditional&lt;BR /&gt;
&amp;gt; SAS DATA step processing where SAS variables are&lt;BR /&gt;
&amp;gt; reset to missing/blank value with each DATA step&lt;BR /&gt;
&amp;gt; pass.  &lt;BR /&gt;
&lt;BR /&gt;
Which variables are initalized to missing?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
1197  options nostimer;&lt;BR /&gt;
1198  data _null_;&lt;BR /&gt;
1199     place='Before';link putall;&lt;BR /&gt;
1200     set sashelp.class(obs=3);&lt;BR /&gt;
1201     place='After ';link putall;&lt;BR /&gt;
1202     return;&lt;BR /&gt;
1203   putall:&lt;BR /&gt;
1204     putlog 'NOTE: ' _N_= (_all_)(=);&lt;BR /&gt;
1205     return;&lt;BR /&gt;
1206     run;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: _N_=1 place=Before NAME=  SEX=  AGE=. HEIGHT=. WEIGHT=.&lt;BR /&gt;
NOTE: _N_=1 place=After NAME=Alfred SEX=M AGE=14 HEIGHT=69 WEIGHT=112.5&lt;BR /&gt;
NOTE: _N_=2 place=Before NAME=Alfred SEX=M AGE=14 HEIGHT=69 WEIGHT=112.5&lt;BR /&gt;
NOTE: _N_=2 place=After NAME=Alice SEX=F AGE=13 HEIGHT=56.5 WEIGHT=84&lt;BR /&gt;
NOTE: _N_=3 place=Before NAME=Alice SEX=F AGE=13 HEIGHT=56.5 WEIGHT=84&lt;BR /&gt;
NOTE: _N_=3 place=After NAME=Barbara SEX=F AGE=13 HEIGHT=65.3 WEIGHT=98&lt;BR /&gt;
NOTE: _N_=4 place=Before NAME=Barbara SEX=F AGE=13 HEIGHT=65.3 WEIGHT=98&lt;BR /&gt;
NOTE: There were 3 observations read from the data set SASHELP.CLASS.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; The position of a RETAIN, when used for&lt;BR /&gt;
&amp;gt; variable ordering also influences a SAS DATA step,&lt;BR /&gt;
&amp;gt; specifically a RETAIN before a SET operates&lt;BR /&gt;
&amp;gt; differently than a RETAIN after a SET.  &lt;BR /&gt;
&lt;BR /&gt;
How so?  Other than other than to estabalish the names in the PDV in the order listed in the retain statement how does position(location) in the data step alter the function of RETAIN.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; I see no  issue with using RETAIN for work variables or those&lt;BR /&gt;
&amp;gt; SAS data step variables passed from macro variables,&lt;BR /&gt;
&amp;gt; but it's when a SAS assignment statement (intended&lt;BR /&gt;
&amp;gt; for output) must be addressed in all cases is what is&lt;BR /&gt;
&amp;gt; concerning to me, due to possibility of lingering&lt;BR /&gt;
&amp;gt; values from prior passes.&lt;BR /&gt;
&lt;BR /&gt;
I got lost again in the distinction you are referring to.  Can you explain this in more detail.  An example would be helpful too.&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
&amp;gt; As mentioned - if it can be avoided.  &lt;BR /&gt;
&amp;gt; Clearly a RETAIN'd variable has its place in a DATA step, when&lt;BR /&gt;
&amp;gt; used appropriately.&lt;BR /&gt;
&lt;BR /&gt;
Avoided for a specific reason?  I am lost again without an example.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Scott Barry&lt;BR /&gt;
&amp;gt; SBBWorks, Inc.</description>
      <pubDate>Tue, 10 Mar 2009 02:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76283#M16502</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T02:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76284#M16503</link>
      <description>&amp;gt;Avoided for a specific reason? I am lost again without an example&lt;BR /&gt;
&lt;BR /&gt;
I recently ran into a macro that had been in production for years.  A new condition in the incoming data left a value unassigned in some cases.  the programmer had not coded for that condition so the retained value from the last assignment ws used.  &lt;BR /&gt;
Yes this was sloppy in the first place, but demonstrates the danger of retaining values.  Now, counter to the argument about the retain statement, ALL variables *created* in a datastep are retained by default, so one must always be careful of this.</description>
      <pubDate>Tue, 10 Mar 2009 12:07:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76284#M16503</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-10T12:07:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76285#M16504</link>
      <description>&amp;gt; &amp;gt;Avoided for a specific reason? I am lost again&lt;BR /&gt;
&amp;gt; without an example&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I recently ran into a macro that had been in&lt;BR /&gt;
&amp;gt; production for years.  A new condition in the&lt;BR /&gt;
&amp;gt; incoming data left a value unassigned in some cases.&lt;BR /&gt;
&amp;gt; the programmer had not coded for that condition so&lt;BR /&gt;
&amp;gt; the retained value from the last assignment ws used.&lt;BR /&gt;
&lt;BR /&gt;
While perhaps not the desired result, it is no fault of RETAIN.   Why was the variable being RETAINed, if it was created in an assignment statement.  &lt;BR /&gt;
&lt;BR /&gt;
If the variable "comes from" SET,MERGE,UPDATE or MODIFY it is not initalized to missing anyway and RETAIN has no effect.  Are you sure you have identifed the problem with the code?&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; s this was sloppy in the first place, but&lt;BR /&gt;
&amp;gt; demonstrates the danger of retaining values.  Now,&lt;BR /&gt;
&amp;gt; counter to the argument about the retain statement,&lt;BR /&gt;
&amp;gt; ALL variables *created* in a datastep are retained by&lt;BR /&gt;
&amp;gt; default, so one must always be careful of this.&lt;BR /&gt;
&lt;BR /&gt;
Are you sure?&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
   RETAIN Statement&lt;BR /&gt;
   --------------------------------------------------------------------------------&lt;BR /&gt;
   Causes a variable that is created by an INPUT or assignment statement to&lt;BR /&gt;
   retain its value from one iteration of the DATA step to the next. &lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Given the above definition it seems rather simple, nothing to fear or avoid.</description>
      <pubDate>Tue, 10 Mar 2009 12:32:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76285#M16504</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T12:32:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76286#M16505</link>
      <description>I am not saying "Don't do it"  As with many things, just be aware of the potential pifalls.&lt;BR /&gt;
&lt;BR /&gt;
See: &lt;A href="http://support.sas.com/publishing/pubcat/chaps/58176.pdf" target="_blank"&gt;http://support.sas.com/publishing/pubcat/chaps/58176.pdf&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
"A Caution When Using a RETAIN Statement&lt;BR /&gt;
There are some serious pitfalls that you can encounter when using the RETAIN statement. For&lt;BR /&gt;
example, suppose you want to read several observations from one SAS data set and create a&lt;BR /&gt;
single observation in a new data set. Under certain circumstances where you have missing values&lt;BR /&gt;
and you are using retained variables, you may make the mistake of using a retained value from a&lt;BR /&gt;
previous subject instead of a missing value for the present subject. We will demonstrate and&lt;BR /&gt;
discuss an example later in this book (see Program 7-7). So think of the RETAIN statement when&lt;BR /&gt;
you need to “remember” information from previous observations, but be especially cautious and&lt;BR /&gt;
test your programs carefully."</description>
      <pubDate>Tue, 10 Mar 2009 12:55:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76286#M16505</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-10T12:55:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76287#M16506</link>
      <description>Yes, the RETAIN statement has its purpose and place in SAS DATA step programming.  It's my personal experience that using the statement should be avoided.  That's all and I have few free cycles to debate the matter further.  Sorry about that.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 10 Mar 2009 13:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76287#M16506</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-10T13:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76288#M16507</link>
      <description>What book is the excerpted from.  I want to see Program 7-7.&lt;BR /&gt;
&lt;BR /&gt;
Sounds like they author is not well informed either.</description>
      <pubDate>Tue, 10 Mar 2009 13:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76288#M16507</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T13:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76289#M16508</link>
      <description>Longitudinal Data and SAS: A Programmer’s Guide&lt;BR /&gt;
&lt;BR /&gt;
Sorry, I wasn't aware that SAS published books by "not well informed" authors.&lt;BR /&gt;
&lt;BR /&gt;
I gladly bow to your greater knowledge.  I guess I have just been halucinating for the past 25 years of SAS programming.</description>
      <pubDate>Tue, 10 Mar 2009 14:10:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76289#M16508</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-10T14:10:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76290#M16509</link>
      <description>Totally agree. You must understand what retain is doing if you are going to use it.&lt;BR /&gt;
&lt;BR /&gt;
Run the following and see what the difference is...&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data testdata;&lt;BR /&gt;
infile cards dsd missover;&lt;BR /&gt;
input name $ month commission debt;&lt;BR /&gt;
cards;&lt;BR /&gt;
James,1,2000,2000&lt;BR /&gt;
James,2,2000,1000&lt;BR /&gt;
James,3,,100&lt;BR /&gt;
James,4,2000,200&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
data retained;&lt;BR /&gt;
retain paid commission name month;&lt;BR /&gt;
set testdata;&lt;BR /&gt;
  if commission ne . and debt ne . then do;&lt;BR /&gt;
    paid=commission-debt;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data not_retained;&lt;BR /&gt;
*retain paid commission name month;&lt;BR /&gt;
set testdata;&lt;BR /&gt;
  if commission ne . and debt ne . then do;&lt;BR /&gt;
    paid=commission-debt;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc compare data=retained c=not_retained;&lt;BR /&gt;
run;

Message was edited by: pznew</description>
      <pubDate>Tue, 10 Mar 2009 14:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76290#M16509</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-10T14:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76291#M16510</link>
      <description>&amp;gt; Longitudinal Data and SAS: A Programmer’s Guide&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Sorry, I wasn't aware that SAS published books by&lt;BR /&gt;
&amp;gt; "not well informed" authors.&lt;BR /&gt;
I don't know but it would seem so.    I would still like to see program 7-7.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; I gladly bow to your greater knowledge.  &lt;BR /&gt;
I don't claim greater knowledge or experience.  I'm just reading the documentation and I see nothing that warrants the cautions that you and SBB are claiming.  I have still not seen any examples.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; I guess I have just been hallucinating for the past 25 years of&lt;BR /&gt;
&amp;gt; SAS programming.&lt;BR /&gt;
I don't know about that but if you have an example where a RETAIN behaves in a way that is contrary to the documentation I would like to see it.</description>
      <pubDate>Tue, 10 Mar 2009 14:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76291#M16510</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T14:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76293#M16512</link>
      <description>&lt;A href="http://ftp.sas.com/samples/A58176" target="_blank"&gt;http://ftp.sas.com/samples/A58176&lt;/A&gt;  For 7-7&lt;BR /&gt;
Sorry, I do not have time to cut out the code I have that was doing this as it is deep in a macro driven system with huge data files.&lt;BR /&gt;
&lt;BR /&gt;
And I say again, I do not disagree that your technique works for arranging variables.  We just need to be aware that there are many beginners on this list who may not be as cognizant of some methods pitfalls.  As in several cases I saw in taking the SAS exams, when asked what would happen if you did this, my first responce was, "I would never do that"&lt;BR /&gt;
&lt;BR /&gt;
So, all I am doing is expressing the need for some caution.</description>
      <pubDate>Tue, 10 Mar 2009 14:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76293#M16512</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-10T14:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76294#M16513</link>
      <description>&amp;gt; Hello Data _null_, &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Yes I totally agree with you data_null, that Retain&lt;BR /&gt;
&amp;gt; statement is very easy and effiecient technique to&lt;BR /&gt;
&amp;gt; rearrange variables. But for starter if he attempts&lt;BR /&gt;
&amp;gt; to caliculate something in the same dataset then the&lt;BR /&gt;
&amp;gt; values might retained . For example sake &lt;BR /&gt;
&lt;BR /&gt;
I see your point.  I was actually trying to get the others who fear RETAIN to provide an example.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Data aa; &lt;BR /&gt;
&amp;gt;   Input Name $3. num1 Num2 ; &lt;BR /&gt;
&amp;gt; talines; &lt;BR /&gt;
&amp;gt; Sam  30  32 &lt;BR /&gt;
&amp;gt; Sam  .   33&lt;BR /&gt;
&amp;gt; Sam  33  . &lt;BR /&gt;
&amp;gt; ;;&lt;BR /&gt;
&amp;gt; Run; &lt;BR /&gt;
&amp;gt; /*This Nice and Easy No Problem in Using Retain */;&lt;BR /&gt;
&amp;gt; Data ss; &lt;BR /&gt;
&amp;gt;    Retain num1 Num2 Name ; &lt;BR /&gt;
&amp;gt; et aa; &lt;BR /&gt;
&amp;gt;   By Name ; &lt;BR /&gt;
&amp;gt; n; &lt;BR /&gt;
&amp;gt; /*A Newbie Like me might do something like this then&lt;BR /&gt;
&amp;gt; value of Sum would be retained for all the&lt;BR /&gt;
&amp;gt; Observations right ?? */;&lt;BR /&gt;
&amp;gt; Data ss1; &lt;BR /&gt;
&amp;gt;    Retain Sum num1 Num2 Name ; &lt;BR /&gt;
&amp;gt; et Ss; By Name ; &lt;BR /&gt;
&amp;gt;  If First.name then  Sum = Num1 +Num2 ; &lt;BR /&gt;
&amp;gt; un; &lt;BR /&gt;
&lt;BR /&gt;
This may not be what you wanted but it works as documented.  &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; So for this reason I have suggested the Origonal&lt;BR /&gt;
&amp;gt; Poster proc sql method where the possiblility of&lt;BR /&gt;
&amp;gt; retain the value would be avoided. &lt;BR /&gt;
&lt;BR /&gt;
Yes a good alternative but must refer to every variable even if you use *.  You can include NOWARN on SQL statement to quiet the noise.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
35   proc sql nowarn;&lt;BR /&gt;
36      create table class as&lt;BR /&gt;
37         select weight,height,* from sashelp.class;&lt;BR /&gt;
NOTE: Table WORK.CLASS created, with 19 rows and 5 columns.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; thanks</description>
      <pubDate>Tue, 10 Mar 2009 15:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76294#M16513</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T15:04:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76295#M16514</link>
      <description>&amp;gt; &lt;A href="http://ftp.sas.com/samples/A58176" target="_blank"&gt;http://ftp.sas.com/samples/A58176&lt;/A&gt;  For 7-7&lt;BR /&gt;
&lt;BR /&gt;
Clearly program 7-7 is too fragile to handle missing times as stated in the document.  However it is NOT the "fault" of RETAIN and there a number of simple fixes that would allow it to handle missing TIMES.  Seem's like a bad example that could have easily been coded to handle missing times.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; Sorry, I do not have time to cut out the code I have&lt;BR /&gt;
&amp;gt; that was doing this as it is deep in a macro driven&lt;BR /&gt;
&amp;gt; system with huge data files.&lt;BR /&gt;
&lt;BR /&gt;
That's fine I have not interesting in seeing that sort of stuff.  I would more interested in an example where RETAIN does not function as documented.&lt;BR /&gt;
&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; And I say again, I do not disagree that your&lt;BR /&gt;
&amp;gt; technique works for arranging variables.  We just&lt;BR /&gt;
&amp;gt; need to be aware that there are many beginners on&lt;BR /&gt;
&amp;gt; this list who may not be as cognizant of some methods&lt;BR /&gt;
&amp;gt; pitfalls.  As in several cases I saw in taking the&lt;BR /&gt;
&amp;gt; SAS exams, when asked what would happen if you did&lt;BR /&gt;
&amp;gt; this, my first response was, "I would never do that"&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; So, all I am doing is expressing the need for some&lt;BR /&gt;
&amp;gt; caution.&lt;BR /&gt;
&lt;BR /&gt;
To me the cautions come without proper explanation like that of SBB that I interpreted as sounding like "there is a problem with RETAIN and it must be avoided".  Those are the kinds of statements that confuse beginners.</description>
      <pubDate>Tue, 10 Mar 2009 15:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76295#M16514</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-03-10T15:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to rearrange variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76296#M16515</link>
      <description>A very simple example of unintended consequenses of inserting a retain statement.&lt;BR /&gt;
&lt;BR /&gt;
Yes this behaves as documented, but if one is not aware of everything happening in a datastep, stuff happens.&lt;BR /&gt;
&lt;BR /&gt;
data one;&lt;BR /&gt;
do x = 1 to 10 ;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
run;&lt;BR /&gt;
data two;&lt;BR /&gt;
retain y x;  * run with and without;&lt;BR /&gt;
set one(rename = (x = y));&lt;BR /&gt;
if y = 3 then x = y;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I think a middle ground is best,  I never say "Never" , just be carefull.&lt;BR /&gt;
And thanks for the discussion to make us all think.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
And now I see why that old macro started acting up:  I tried out your technique of putting in a retain to order the variables, there was a rename in the macro.  So it retained the value when it got to a missing value.  since the datastep has several macro calls and 350 variables and 10**9 records it took a while to find the cause.&lt;BR /&gt;
&lt;BR /&gt;
So yea, even an old timer like me can make a mistake.

Message was edited by: Flip</description>
      <pubDate>Tue, 10 Mar 2009 16:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-rearrange-variables/m-p/76296#M16515</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-03-10T16:30:39Z</dc:date>
    </item>
  </channel>
</rss>

