<?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: Remove numbers presented in the middle or end of a string column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938137#M368536</link>
    <description>&lt;P&gt;This may be close.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    infile cards truncover;
    input text $100.;
    if _n_ eq 1 then do;
       /* Pattern to remove digit strings that are not part of a word */
       pattern_all_digits = prxparse("s/\b\d+\b//");
       /* Pattern to detect digit strings at the beginning of the sentence */
       pattern_leading_digits = prxparse("/^\d+/");
       retain pattern_:;
       end;    
    /* Initialize variables */
    new_text = text;

    /* Check for leading digits and preserve them if found */
    if prxmatch(pattern_leading_digits, text) then do;
        length leading_digits $20.;
        call prxsubstr(pattern_leading_digits, text, position, length);
        leading_digits = substr(text, position, length);
        new_text = prxchange(pattern_all_digits, -1, substr(text, length+1));
        new_text = catx(' ', leading_digits, new_text);
    end;
    else do;
        new_text = prxchange(pattern_all_digits, -1, text);
    end;

    drop pattern_all_digits pattern_leading_digits position length leading_digits;
datalines;
123 Here are some numbers: 123, 456, and 789.
This string has no numbers.
42 A single number: 42.
More numbers: 333, 7777.
99 Another example 100 200.
abc123def Keep digits in words like abc123def.
123abc Also keep digits in words like 123abc.
;
run;

proc print data=example;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 499px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99004iDE7FB087E2986C1B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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/454358"&gt;@sam88r&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I really appreciate your help.&amp;nbsp; Would it possible to adjust the code to not to remove the digits in these kind of scenarios?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ex: XXX1222 YYYY, SSS1222 TYYYY 1222&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the outputs of these kind of scenarios would be :&lt;/P&gt;
&lt;P&gt;XXX1222 YYYY, SSS1222 TYYYY&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>Fri, 02 Aug 2024 21:32:10 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2024-08-02T21:32:10Z</dc:date>
    <item>
      <title>Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938112#M368530</link>
      <description>&lt;P&gt;I have a SAS table with a column data. The data&amp;nbsp; column will contain values like this: XXXX 1123 YYY , SSSSA 1 WWW 3 QQQ, EEE WWS 122, 123 XASS WYSS&lt;/P&gt;&lt;P&gt;I want to remove the numeric terms in the middle. So the desired output looks like this:&lt;/P&gt;&lt;P&gt;XXXX YYY , SSSSA WWW QQQ, EEE WWS,&amp;nbsp;123 XASS WYSS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I started with this code (to remove the numbers irrespective of the position) but it doesnt give me the answer I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want;

set have;

array word[100] $20 _temporary_;

length result $200;

result=' ';

do i=1 to countw(data, ' ');

&amp;nbsp; word[i]=scan(data,i,' ');

&amp;nbsp; &amp;nbsp; if notdigit(word[i]) then do;

&amp;nbsp; &amp;nbsp; &amp;nbsp;result=catx(' ' , result, word[i]);

&amp;nbsp; &amp;nbsp;end;

end;

run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Can anyone help me to fix the issue and get the desired results?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 20:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938112#M368530</guid>
      <dc:creator>sam88r</dc:creator>
      <dc:date>2024-08-02T20:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938116#M368531</link>
      <description>&lt;P&gt;Not sure if you want the digit strings or to remove them.&amp;nbsp; This removes them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    input text $50.;
    pattern = prxparse("s/\d+//");
    new_text = prxchange(pattern, -1, text);
    drop pattern;
datalines;
Here are some numbers: 123, 456, and 789.
This string has no numbers.
A single number: 42.
More numbers: 333, 7777.
;
run;

proc print data=example;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data_null___0-1722631865971.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98991i28D4DE90D6C67FDB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="data_null___0-1722631865971.png" alt="data_null___0-1722631865971.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 20:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938116#M368531</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-08-02T20:52:13Z</dc:date>
    </item>
    <item>
      <title>Re: Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938119#M368532</link>
      <description>&lt;P&gt;I think this is it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    infile cards truncover;
    input text $100.;
    pattern_all_digits = prxparse("s/\d+//");
    pattern_leading_digits = prxparse("/^\d+/");

    /* Initialize variables */
    new_text = text;

    /* Check for leading digits and preserve them if found */
    if prxmatch(pattern_leading_digits, text) then do;
        length leading_digits $20.;
        call prxsubstr(pattern_leading_digits, text, position, length);
        leading_digits = substr(text, position, length);
        new_text = prxchange(pattern_all_digits, -1, substr(text, length+1));
        new_text = catx(' ', leading_digits, new_text);
    end;
    else do;
        new_text = prxchange(pattern_all_digits, -1, text);
    end;

    drop pattern_all_digits pattern_leading_digits position length leading_digits;
datalines;
123 Here are some numbers: 123, 456, and 789.
This string has no numbers.
42 A single number: 42.
More numbers: 333, 7777.
99 Another example 100 200.
;
run;

proc print data=example;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="data_null___0-1722632474522.png" style="width: 471px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98992i557BA5CD18743474/image-dimensions/471x132?v=v2" width="471" height="132" role="button" title="data_null___0-1722632474522.png" alt="data_null___0-1722632474522.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 21:02:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938119#M368532</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-08-02T21:02:12Z</dc:date>
    </item>
    <item>
      <title>Re: Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938132#M368534</link>
      <description>&lt;P&gt;I really appreciate your help.&amp;nbsp; Would it possible to adjust the code to not to remove the digits in these kind of scenarios?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ex: XXX1222 YYYY, SSS1222 TYYYY 1222&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the outputs of these kind of scenarios would be :&lt;/P&gt;&lt;P&gt;XXX1222 YYYY, SSS1222 TYYYY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 21:22:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938132#M368534</guid>
      <dc:creator>sam88r</dc:creator>
      <dc:date>2024-08-02T21:22:01Z</dc:date>
    </item>
    <item>
      <title>Re: Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938137#M368536</link>
      <description>&lt;P&gt;This may be close.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
    infile cards truncover;
    input text $100.;
    if _n_ eq 1 then do;
       /* Pattern to remove digit strings that are not part of a word */
       pattern_all_digits = prxparse("s/\b\d+\b//");
       /* Pattern to detect digit strings at the beginning of the sentence */
       pattern_leading_digits = prxparse("/^\d+/");
       retain pattern_:;
       end;    
    /* Initialize variables */
    new_text = text;

    /* Check for leading digits and preserve them if found */
    if prxmatch(pattern_leading_digits, text) then do;
        length leading_digits $20.;
        call prxsubstr(pattern_leading_digits, text, position, length);
        leading_digits = substr(text, position, length);
        new_text = prxchange(pattern_all_digits, -1, substr(text, length+1));
        new_text = catx(' ', leading_digits, new_text);
    end;
    else do;
        new_text = prxchange(pattern_all_digits, -1, text);
    end;

    drop pattern_all_digits pattern_leading_digits position length leading_digits;
datalines;
123 Here are some numbers: 123, 456, and 789.
This string has no numbers.
42 A single number: 42.
More numbers: 333, 7777.
99 Another example 100 200.
abc123def Keep digits in words like abc123def.
123abc Also keep digits in words like 123abc.
;
run;

proc print data=example;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 499px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99004iDE7FB087E2986C1B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&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/454358"&gt;@sam88r&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I really appreciate your help.&amp;nbsp; Would it possible to adjust the code to not to remove the digits in these kind of scenarios?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ex: XXX1222 YYYY, SSS1222 TYYYY 1222&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the outputs of these kind of scenarios would be :&lt;/P&gt;
&lt;P&gt;XXX1222 YYYY, SSS1222 TYYYY&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>Fri, 02 Aug 2024 21:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938137#M368536</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2024-08-02T21:32:10Z</dc:date>
    </item>
    <item>
      <title>Re: Remove numbers presented in the middle or end of a string column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938161#M368546</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example;
infile cards dsd;
    input text :$50. @@;
datalines;
XXX1222 YYYY, SSS1222 TYYYY 1222
XXXX 1123 YYY , SSSSA 1 WWW 3 QQQ, EEE WWS 122, 123 XASS WYSS
;
run;
data want;
 set example;
 want=prxchange('s/\s\d+\b//',-1,text);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1722670014654.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99005i97B45ABA3B68883F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1722670014654.png" alt="Ksharp_0-1722670014654.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Aug 2024 07:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-numbers-presented-in-the-middle-or-end-of-a-string-column/m-p/938161#M368546</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-08-03T07:28:24Z</dc:date>
    </item>
  </channel>
</rss>

