<?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: Replace a character in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957406#M373750</link>
    <description>&lt;P&gt;For this particular situation, you can also use the following weird SAS syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(V,2,1)='X';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...where V is whatever your variable name is.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jan 2025 00:18:26 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-01-28T00:18:26Z</dc:date>
    <item>
      <title>Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957343#M373727</link>
      <description>&lt;P&gt;Good Afternoon, I have a 7 character variable in a dataset. I want to replace 'X' in the 2nd position from left with a '0'&amp;nbsp; in this variable. And same way in a different dataset, replace '0' in the 2nd position from left with 'X'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1st dataset:&lt;/P&gt;&lt;P&gt;I have: 0&lt;FONT color="#FF6600"&gt;&lt;U&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;12345&lt;/P&gt;&lt;P&gt;I want: 0&lt;FONT color="#FF6600"&gt;&lt;U&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;12345&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2nd dataset:&lt;/P&gt;&lt;P&gt;I have: 0&lt;FONT color="#0000FF"&gt;&lt;U&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;12345&lt;/P&gt;&lt;P&gt;I want: 0&lt;FONT color="#0000FF"&gt;&lt;U&gt;&lt;STRONG&gt;X&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;12345&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 19:43:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957343#M373727</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2025-01-27T19:43:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957345#M373729</link>
      <description>&lt;P&gt;For data set 1, this is what you would do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(variablename,2,1)='X' then substr(variablename,2,1)='0';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I leave it to you as a homework assignment to write the code needed (as a modification of the above code) for data set 2.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 20:01:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957345#M373729</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-01-27T20:01:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957367#M373735</link>
      <description>&lt;P&gt;Thank you for your reply. Below is what I did.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;set dropnulls;&lt;BR /&gt;if substr(pol_nbr,2,1)='X' then rpol_nbr = substr(pol_nbr,2,1)='0';&lt;BR /&gt;where pol_nm is missing;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am getting 0 in the field where 2nd position letter is X.&lt;/P&gt;&lt;P&gt;for an example, for a value of 0&lt;STRONG&gt;&lt;FONT color="#FFCC00"&gt;X&lt;/FONT&gt;&lt;/STRONG&gt;04236 I am getting 0 in the field instead of 0&lt;FONT color="#FFCC00"&gt;0&lt;/FONT&gt;04236.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 21:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957367#M373735</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2025-01-27T21:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957372#M373740</link>
      <description>&lt;P&gt;I think I figured it out. Thank you for all your help. I appreciate it.&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jan 2025 21:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957372#M373740</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2025-01-27T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957406#M373750</link>
      <description>&lt;P&gt;For this particular situation, you can also use the following weird SAS syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(V,2,1)='X';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...where V is whatever your variable name is.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 00:18:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957406#M373750</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-28T00:18:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957416#M373754</link>
      <description>&lt;P&gt;thank you for your reply.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jan 2025 01:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-character-in-a-string/m-p/957416#M373754</guid>
      <dc:creator>SASMom2</dc:creator>
      <dc:date>2025-01-28T01:44:13Z</dc:date>
    </item>
  </channel>
</rss>

