<?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 How to delete one numeric value from a string variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435354#M68948</link>
    <description>&lt;P&gt;I have a dataset with a&amp;nbsp;character variable called "oldvar" that contains a string of numeric values such as "4 6 6 4 5". I would like to create a new variable that&amp;nbsp;has one of the "4" values removed. For example, I would like my new variable to be "6 6 4 5" with the first 4 deleted or alternatively the new variable could be "4 6 6 5". Either one&amp;nbsp;would work for me. I've tried using a combination of the substr and index functions but none have produced what I'm looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of values that "oldvar" takes on:&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 5 4 5&lt;/P&gt;&lt;P&gt;4 6 4&lt;/P&gt;&lt;P&gt;6 6 4 5&lt;/P&gt;&lt;P&gt;3 4 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for any help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Feb 2018 17:24:23 GMT</pubDate>
    <dc:creator>Jaime2</dc:creator>
    <dc:date>2018-02-08T17:24:23Z</dc:date>
    <item>
      <title>How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435354#M68948</link>
      <description>&lt;P&gt;I have a dataset with a&amp;nbsp;character variable called "oldvar" that contains a string of numeric values such as "4 6 6 4 5". I would like to create a new variable that&amp;nbsp;has one of the "4" values removed. For example, I would like my new variable to be "6 6 4 5" with the first 4 deleted or alternatively the new variable could be "4 6 6 5". Either one&amp;nbsp;would work for me. I've tried using a combination of the substr and index functions but none have produced what I'm looking for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of values that "oldvar" takes on:&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 5 4 5&lt;/P&gt;&lt;P&gt;4 6 4&lt;/P&gt;&lt;P&gt;6 6 4 5&lt;/P&gt;&lt;P&gt;3 4 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance for any help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 17:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435354#M68948</guid>
      <dc:creator>Jaime2</dc:creator>
      <dc:date>2018-02-08T17:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435367#M68951</link>
      <description>&lt;P&gt;What's the rules?&lt;BR /&gt;How do you know what to delete and what to keep?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192263"&gt;@Jaime2&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a dataset with a&amp;nbsp;character variable called "oldvar" that contains a string of numeric values such as "4 6 6 4 5". I would like to create a new variable that&amp;nbsp;has one of the "4" values removed. For example, I would like my new variable to be "6 6 4 5" with the first 4 deleted or alternatively the new variable could be "4 6 6 5". Either one&amp;nbsp;would work for me. I've tried using a combination of the substr and index functions but none have produced what I'm looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example of values that "oldvar" takes on:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4 5 4 5&lt;/P&gt;
&lt;P&gt;4 6 4&lt;/P&gt;
&lt;P&gt;6 6 4 5&lt;/P&gt;
&lt;P&gt;3 4 3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for any help!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 17:46:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435367#M68951</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-08T17:46:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435368#M68952</link>
      <description>&lt;P&gt;So what is the final desired product from your data set?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this what you want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="168"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="104"&gt;have&lt;/TD&gt;
&lt;TD width="64"&gt;want&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4 5 4 5&lt;/TD&gt;
&lt;TD&gt;5 4 5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;4 6 4&lt;/TD&gt;
&lt;TD&gt;6 4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6 6 4 5&lt;/TD&gt;
&lt;TD&gt;6 6 5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;3 4 3&lt;/TD&gt;
&lt;TD&gt;3 3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 08 Feb 2018 17:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435368#M68952</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-02-08T17:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435372#M68953</link>
      <description>&lt;P&gt;Yes, this is exactly what I want to achieve.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 18:05:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435372#M68953</guid>
      <dc:creator>Jaime2</dc:creator>
      <dc:date>2018-02-08T18:05:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435374#M68954</link>
      <description>&lt;P&gt;I'm creating control cards for another program. The rule is to literally "delete one "4" from the string of values." There is always at least one "4" in the variable, sometimes there are 2 or 3 of them. Thanks for asking.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 18:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435374#M68954</guid>
      <dc:creator>Jaime2</dc:creator>
      <dc:date>2018-02-08T18:10:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435377#M68956</link>
      <description>&lt;P&gt;One approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;found4 = indexw(oldvar, '4');&lt;/P&gt;
&lt;P&gt;select (found4);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; when (0);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; when (1) oldvar = substr(oldvar, 3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; otherwise oldvar = catx(' ', substr(oldvar, 1, found4 - 1), substr(oldvar, found4 + 1)) ;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop found4;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sure there are ways to do this with parsing functions, but I'm not as familiar with them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;************ EDITED:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#ff0000"&gt;See the &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/6401"&gt;@HB&lt;/a&gt;&amp;nbsp;solution below.&amp;nbsp; There's a good reason to learn parsing functions.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:50:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435377#M68956</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-08T19:50:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435403#M68958</link>
      <description>&lt;P&gt;Here's another approach just for options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input oldvar $20.;
datalines;
4 5 4 5
4 6 4
6 6 4 5
3 4 3
;
run;

data want;
	set have;
	newvar= prxchange('s/4 //', 1, oldvar); 
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This yields&lt;/P&gt;
&lt;TABLE width="158"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;The SAS System&lt;/TD&gt;
&lt;TD width="53"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;oldvar&lt;/TD&gt;
&lt;TD width="53"&gt;newvar&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;4 5 4 5&lt;/TD&gt;
&lt;TD width="53"&gt;5 4 5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;4 6 4&lt;/TD&gt;
&lt;TD width="53"&gt;6 4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;6 6 4 5&lt;/TD&gt;
&lt;TD width="53"&gt;6 6 5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="105"&gt;3 4 3&lt;/TD&gt;
&lt;TD width="53"&gt;3 3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The documentation:&lt;/P&gt;
&lt;PRE&gt;prxchange('s/world/planet/', 1, 'Hello world!'); &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where&lt;/P&gt;
&lt;TABLE class="largeSpace" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR valign="top" align="left"&gt;
&lt;TD&gt;s&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;specifies the metacharacter for substitution.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top" align="left"&gt;
&lt;TD&gt;&lt;SPAN class="emph"&gt;world&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;specifies the regular expression.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top" align="left"&gt;
&lt;TD&gt;&lt;SPAN class="emph"&gt;planet&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;specifies the replacement value for &lt;SPAN class="emph"&gt;world&lt;/SPAN&gt;.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top" align="left"&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;specifies that the search ends when one match is found.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR valign="top" align="left"&gt;
&lt;TD&gt;&lt;SPAN class="emph"&gt;Hello world!&lt;/SPAN&gt;&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;specifies the source string to be searched.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case: s, 4 and a space, nothing (//), 1, and the old variable.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435403#M68958</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2018-02-08T19:50:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435405#M68959</link>
      <description>&lt;P&gt;Thank you very much! Your solution also worked just fine!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435405#M68959</guid>
      <dc:creator>Jaime2</dc:creator>
      <dc:date>2018-02-08T19:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to delete one numeric value from a string variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435407#M68960</link>
      <description>&lt;P&gt;Your solution worked - thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Feb 2018 19:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-delete-one-numeric-value-from-a-string-variable/m-p/435407#M68960</guid>
      <dc:creator>Jaime2</dc:creator>
      <dc:date>2018-02-08T19:56:17Z</dc:date>
    </item>
  </channel>
</rss>

