<?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: Swap Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761040#M240749</link>
    <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;rename x=tmp y=x tmp=y;&lt;/FONT&gt; &lt;BR /&gt;in proc datasets works too.&lt;BR /&gt;Rewriting the whole table is undesirable &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&lt;/P&gt;</description>
    <pubDate>Thu, 12 Aug 2021 00:35:32 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-08-12T00:35:32Z</dc:date>
    <item>
      <title>Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760829#M240642</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ds;
X=10;
Y=9;
run;

data ds1;
retain X Y ;
set ds (rename=(X=Y Y=X));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Any other method to swap the values without using arrays&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 06:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760829#M240642</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-08-11T06:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760843#M240647</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table ds1 as
  select Y as X
       , X as Y from ds;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, if you don't want to specify your own variables, I think you can do it using macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 07:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760843#M240647</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-08-11T07:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760845#M240648</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe:&lt;/P&gt;
&lt;PRE&gt;data ds;
X=10;
Y=9;
run;
&lt;BR /&gt;proc datasets library=work nodetails nolist;
 modify ds;
 rename x=ytemp
        y=xtemp
 ;
 modify ds;
 rename ytemp=y
        xtemp=x
 ;
run;
quit;

proc print data=ds;
run;
&lt;/PRE&gt;
&lt;P&gt;Proc datasets won't let you rename a variable to another variable in the data set so requires two Modify blocks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Advantage with Proc Datasets is that there is no reading of record by record as a Set statement uses. So will execute faster with moderate sized data sets or larger. And doesn't create another data set if that really isn't desired.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 07:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760845#M240648</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-11T07:54:38Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760847#M240650</link>
      <description>&lt;P&gt;Hi kawakami&lt;/P&gt;
&lt;P&gt;how to reorder after giving alias name for defined variales x ,y&amp;nbsp; in proc sql&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 07:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760847#M240650</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2021-08-11T07:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760884#M240673</link>
      <description>&lt;P&gt;This works too:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work nodetails nolist;
 modify ds;
 rename x=ytemp
        y=xtemp
 ;
 rename ytemp=y
        xtemp=x
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Aug 2021 10:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760884#M240673</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-11T10:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760894#M240679</link>
      <description>&lt;PRE&gt;data ds;
X=10;
Y=9;
run;

data ds1;
set ds (rename=(X=_X Y=X _X=Y));
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Aug 2021 12:16:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760894#M240679</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-11T12:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760916#M240692</link>
      <description>&lt;P&gt;Yep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Style habits involved with making sure I can tell later explicitly which data set is getting modified just like I practically never allow use of the _last_ data set as the data for a proc.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 14:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760916#M240692</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-11T14:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760962#M240713</link>
      <description>&lt;P&gt;Good approach.&amp;nbsp; I would not be shocked if this actually worked:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work nodetails nolist;
 modify ds;
 rename x=y  y=x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you try it?&amp;nbsp; (Sorry, I no longer have the software available to test it myself.)&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 16:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760962#M240713</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-08-11T16:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760973#M240716</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Good approach.&amp;nbsp; I would not be shocked if this actually worked:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work nodetails nolist;
 modify ds;
 rename x=y  y=x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Did you try it?&amp;nbsp; (Sorry, I no longer have the software available to test it myself.)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes I tried that first though something in the back of mind whispered "I don't think this will work." from other places where Proc Datasets seems a bit touchier than the data step for some things.&lt;/P&gt;
&lt;PRE&gt;5    proc datasets library=work nodetails nolist;
NOTE: Writing HTML Body file: sashtml.htm
6     modify ds;
7     rename x=y  y=x;
ERROR: Variable y already exists on file WORK.DS.
ERROR: Variable x already exists on file WORK.DS.
8    run;

NOTE: Statements not processed because of errors noted above.
&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Aug 2021 17:43:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/760973#M240716</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-11T17:43:19Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761040#M240749</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;rename x=tmp y=x tmp=y;&lt;/FONT&gt; &lt;BR /&gt;in proc datasets works too.&lt;BR /&gt;Rewriting the whole table is undesirable &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 00:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761040#M240749</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-12T00:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761122#M240791</link>
      <description>Sure . if it was a big table .&lt;BR /&gt;If it was a small table ,it doesn't matter whether use Data Step or Proc Datasets .</description>
      <pubDate>Thu, 12 Aug 2021 12:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761122#M240791</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-12T12:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: Swap Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761306#M240883</link>
      <description>&lt;P&gt;But you don't know if it was a large table. Plus rewriting the data presents potential downsides other than performance, such as losing indexes or sort order, resetting the create date, or changing OS attributes such as the owner.&lt;/P&gt;
&lt;P&gt;As a matter of habit, data steps really should not be used just to change attributes.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Aug 2021 22:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Swap-Values/m-p/761306#M240883</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-08-12T22:50:04Z</dc:date>
    </item>
  </channel>
</rss>

