<?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 Switch Column Values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201829#M37678</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to set a conditional statement such that if the first character of column "B" is a number, the values of columns "A" and "B" should be switched.&amp;nbsp; Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Phil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 15 Mar 2015 17:00:03 GMT</pubDate>
    <dc:creator>PhillipSherlock</dc:creator>
    <dc:date>2015-03-15T17:00:03Z</dc:date>
    <item>
      <title>Switch Column Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201829#M37678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to set a conditional statement such that if the first character of column "B" is a number, the values of columns "A" and "B" should be switched.&amp;nbsp; Any suggestions would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Phil&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 17:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201829#M37678</guid>
      <dc:creator>PhillipSherlock</dc:creator>
      <dc:date>2015-03-15T17:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Column Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201830#M37679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suggest using a DATA step where SAS assignment statements use the ANYDIGIT along with a H_xxxx (hold variable) for your conditional assignment.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is unspecified here is whether your objective is on an SAS observation level basis or if only one occurrence is different, then switch all observations -- there you might consider a DATA step to test values, then a conditional PROC DATASETS to effect a change on the entire dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.sas.com/kb/35/758.html" title="https://support.sas.com/kb/35/758.html"&gt;35758 - New "ANY" functions in SAS® 9 and later releases can search for various types of characters in a string&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scott Barry&lt;BR /&gt;SBBWorks, Inc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 17:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201830#M37679</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2015-03-15T17:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Switch Column Values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201831#M37680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, without data it's not entirely clear what you want. I read this as you want the "new" B value to become the value for A, IF the first character of "old B" value is a number/digit and you want to switch the A value to the "new" B?&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="9564" alt="forum_switch_values.png" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/9564_forum_switch_values.png" width="450" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is this what you meant? If so, assuming the data (WORK.FAKEDATA) shown in the first PROC PRINT, this program using ANYDIGIT and SUBSTR does the swap. You can look in the doc to find out what those functions do, as well as looking up the RENAME= option. Of course, you may need to tweak the program based on the real names and lengths of your real variables. The Final dataset is called WORK.SWITCH.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cynthia&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;data switch;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; set fakedata(rename=(b=oldb));&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; if anydigit(substr(oldb,1,1)) = 1 then do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = a;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a=oldb;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; else do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b = oldb;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;proc print data=switch;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; title 'Switched data (can drop OLDB var after verifying)';&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;&amp;nbsp; var a b oldb;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&lt;STRONG&gt;title;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 15 Mar 2015 18:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Switch-Column-Values/m-p/201831#M37680</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2015-03-15T18:14:24Z</dc:date>
    </item>
  </channel>
</rss>

