<?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 Retain Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91615#M257431</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to combine two sas datasets horizontally and i would like the new output file have columns placed in certain order.&amp;nbsp; I use RETAIN to set the order of the columns as shown below.&amp;nbsp; However, the output i get is not what I expected.&amp;nbsp; The column 'new_month' from in_file2 should be placed as the last column.&amp;nbsp; For the sake of simplying the discussion, i have listed the column names.&amp;nbsp; Does anyone have any suggestions on how I can list the columns in the desired order?&amp;nbsp; Thank you very much any any input ! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new_file;&lt;/P&gt;&lt;P&gt;retain&amp;nbsp; _name&amp;nbsp; _step _m:&amp;nbsp; new_month;&lt;/P&gt;&lt;P&gt;set in_file1;&lt;/P&gt;&lt;P&gt;set in_file2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In_file1:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp; _Step _m1 _m2 _m3 .... _m11&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In_file2:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;new_month&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp; _Step&amp;nbsp; &lt;STRONG&gt;new_month &lt;/STRONG&gt; _m1 _m2 _m3 ... _m11&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Desire Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp;&amp;nbsp; _Step&amp;nbsp; _m1 _m2 _m3... _m11 &lt;STRONG&gt;new_month&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Dec 2012 23:07:40 GMT</pubDate>
    <dc:creator>KevinC_</dc:creator>
    <dc:date>2012-12-05T23:07:40Z</dc:date>
    <item>
      <title>Retain Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91615#M257431</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to combine two sas datasets horizontally and i would like the new output file have columns placed in certain order.&amp;nbsp; I use RETAIN to set the order of the columns as shown below.&amp;nbsp; However, the output i get is not what I expected.&amp;nbsp; The column 'new_month' from in_file2 should be placed as the last column.&amp;nbsp; For the sake of simplying the discussion, i have listed the column names.&amp;nbsp; Does anyone have any suggestions on how I can list the columns in the desired order?&amp;nbsp; Thank you very much any any input ! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data new_file;&lt;/P&gt;&lt;P&gt;retain&amp;nbsp; _name&amp;nbsp; _step _m:&amp;nbsp; new_month;&lt;/P&gt;&lt;P&gt;set in_file1;&lt;/P&gt;&lt;P&gt;set in_file2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In_file1:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp; _Step _m1 _m2 _m3 .... _m11&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;In_file2:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;new_month&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp; _Step&amp;nbsp; &lt;STRONG&gt;new_month &lt;/STRONG&gt; _m1 _m2 _m3 ... _m11&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Desire Output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;_Name&amp;nbsp;&amp;nbsp; _Step&amp;nbsp; _m1 _m2 _m3... _m11 &lt;STRONG&gt;new_month&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 23:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91615#M257431</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2012-12-05T23:07:40Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91616#M257432</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The whole purpose of using the RETAIN statement as a trick to re-order the variables is that it is the first place where the variables are referenced. So of course you cannot use a variable list using the : suffix because that will match existing names. But there are no existing names at that point.&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;retain&amp;nbsp; _name&amp;nbsp; _step _m1-_m12&amp;nbsp; new_month;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Dec 2012 23:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91616#M257432</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-05T23:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91617#M257433</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could construct a macro variable containing the list of the _m prefixed variables prior to the datastep and feed that list into the RETAIN statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Somewhat like&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select name into :mlist separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where upcase(libname)='WORK'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and upcase(memname)='IN_FILE1'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and upcase(name) eqt '_M'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data new_file ;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain&amp;nbsp; _name&amp;nbsp; _step&amp;nbsp; &amp;amp;mlist&amp;nbsp; new_month;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* rest of your code */&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Unless I totally screwed up my tests (on z/OS, SAS 9.1.3) that should work.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;(Caveat: due to cut/paste being restricted on my z/OS connection, I had to retype the above code by hand.)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Robert&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Missing closing quote added after "='IN_FILE1" in SQL step. (Robert, 07dec2012:07:08 GMT+1)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 10:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91617#M257433</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2012-12-06T10:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Retain Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91618#M257434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you Robert and Tom for your input!&amp;nbsp; Both of your suggestions make great sense.&amp;nbsp; I will try them out when I get in. &lt;/P&gt;&lt;P&gt;Robert, thank you for manually typing the code in here.&amp;nbsp; Your input is greatly appreciated!&amp;nbsp; Thank you both &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 06 Dec 2012 22:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-Question/m-p/91618#M257434</guid>
      <dc:creator>KevinC_</dc:creator>
      <dc:date>2012-12-06T22:12:38Z</dc:date>
    </item>
  </channel>
</rss>

