<?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 Find the first occurrence of character in a string. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878823#M347204</link>
    <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I have a string as this: 1234568F888.&lt;/P&gt;
&lt;P&gt;I need to find the position of the character in this string.&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;
&lt;P&gt;Blue&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jun 2023 20:45:09 GMT</pubDate>
    <dc:creator>GN0001</dc:creator>
    <dc:date>2023-06-01T20:45:09Z</dc:date>
    <item>
      <title>Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878823#M347204</link>
      <description>&lt;P&gt;Hello team,&lt;/P&gt;
&lt;P&gt;I have a string as this: 1234568F888.&lt;/P&gt;
&lt;P&gt;I need to find the position of the character in this string.&lt;/P&gt;
&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;
&lt;P&gt;Blue&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 20:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878823#M347204</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-01T20:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878826#M347206</link>
      <description>&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1m0n4833qyto5n1e793r44uuozv.htm" target="_blank" rel="noopener"&gt;NOTDIGIT Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 20:48:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878826#M347206</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-01T20:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878828#M347207</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd use prxmatch to get the index.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;example below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
have = "1234568F888";
want = prxmatch('([A-Za-z])',have);
put want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thanks&lt;/P&gt;
&lt;P&gt;harry&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 20:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878828#M347207</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2023-06-01T20:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878832#M347215</link>
      <description>&lt;P&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p0s3647o5kwnnin0zcht0s5p9f1l.htm" target="_self"&gt;ANYALPHA&lt;/A&gt; function would also work here&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 21:13:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878832#M347215</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-01T21:13:31Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878848#M347222</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to use anyalpha, but I couldn't.&lt;/P&gt;
&lt;P&gt;Can you please kindly guide me?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blue&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878848#M347222</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-01T22:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878851#M347224</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hello Harry,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;This didn't work. it gave me 17.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thanks for your input anyway.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Respectfully,&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Blue&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:06:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878851#M347224</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-01T22:06:38Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878854#M347225</link>
      <description>I used Anyalpha, that gave me number 17.&lt;BR /&gt;I need to use this in a substr function, to get all the string till 17 or till whatever number Anyalpha gives.&lt;BR /&gt;Regards,&lt;BR /&gt;blue</description>
      <pubDate>Thu, 01 Jun 2023 22:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878854#M347225</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-01T22:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878857#M347227</link>
      <description>&lt;P&gt;Hi Blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's odd it gave you 17. I've just re-ran it in my environment, it gives me the correct position at 8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1685657713493.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84632iCAC061FAB2B0760A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1685657713493.png" alt="HarrySnart_0-1685657713493.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it giving you 17 when you apply it to your real dataset?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks&lt;/P&gt;
&lt;P&gt;Harry&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878857#M347227</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2023-06-01T22:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878863#M347232</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if you're getting 17 with both PRXPARSE and ANYALPHA then it sounds like you just need to do the substring from this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can feed the output of either approach into the SUBSTR function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
have = "1234568F888";
want = prxmatch('([A-Za-z])',have);
put "character at: " want;
/* substring until char */
want2 = substr(have,1,want-1); *everything until F;
want3 = substr(have,want+1); *everything after F;
put want2;
put want3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1685658233292.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84633i633250BC151E4329/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1685658233292.png" alt="HarrySnart_0-1685658233292.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878863#M347232</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2023-06-01T22:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878866#M347235</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried to use anyalpha, but I couldn't.&lt;/P&gt;
&lt;P&gt;Can you please kindly guide me?&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;blue&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;We have talked about this. Do not say it doesn't work without giving more information — specifically we need you to provide the code you tried, the input data (if it is not in the code itself) and the output. And we shouldn't have to ask for this in every thread.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 22:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878866#M347235</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-01T22:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878871#M347240</link>
      <description>&lt;P&gt;So are you using a double byte character set?&amp;nbsp; That might return 17 instead of 9 since each character would take 2 bytes in the string the 9 character would start in the 17th byte.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps your string has leading spaces that you are not seeing either because you use PUT with the $ format instead of the $CHAR or $QUOTE format.&amp;nbsp; Or you looked that the ODS output instead of the LISTING (PRINT) output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2023 23:16:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878871#M347240</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-01T23:16:01Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878901#M347254</link>
      <description>Yes correct, it gave me number 17 on my own data.&lt;BR /&gt;I used it in in substr, &lt;BR /&gt;Thanks for it, &lt;BR /&gt;Respectfully, &lt;BR /&gt;Blue blue</description>
      <pubDate>Fri, 02 Jun 2023 05:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878901#M347254</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-02T05:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878902#M347255</link>
      <description>I acknowledged it, but input data was member Id. If I share it, I can be jailed. My input data is personal health information, I can’t share it. I have mentioned it several times. &lt;BR /&gt;I always Google before posting my question to this forum if I can’t find the answer, or if I find the answer, again I want to make sure that what I am trying to do is 100 percent correct. &lt;BR /&gt;Please kindly bear with me.&lt;BR /&gt;Regards&lt;BR /&gt;Blue</description>
      <pubDate>Fri, 02 Jun 2023 05:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878902#M347255</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2023-06-02T05:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878903#M347256</link>
      <description>&lt;P&gt;For the data you presented, the suggested methods work, period.&lt;/P&gt;
&lt;P&gt;Applying those methods to your real data is now your task. Different data, different results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need further help, supply&amp;nbsp;&lt;U&gt;usable example data&lt;/U&gt; (DATA step with DATALINES) where you make up fake data which resembles the original data structure, and show the expected result from this fake data.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 06:03:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878903#M347256</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-06-02T06:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: Find the first occurrence of character in a string.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878924#M347261</link>
      <description>&lt;P&gt;If you're really dealing with a multibyte character set then you need to tell us clearly. For a multibyte character set one can only use string functions on&amp;nbsp;&amp;nbsp;I18N Level 2.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which functions are suitable is fully documented &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/p1pca7vwjjwucin178l8qddjn0gi.htm" target="_self"&gt;here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From what you write I believe you want the substring of digits up-to the first character in the string. If so then why not use the scan() function ...or kscanx() for multibyte.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  infile datalines truncover;
  input str $20.;
  first_char_pos=kfindc(str,,'kd');
  digits_until_first_char=kscanx(str,1,'','kd');
  datalines;
1234568F888
;
proc print data=test;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1685698845874.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/84649iD7EA300AD612D900/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1685698845874.png" alt="Patrick_0-1685698845874.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2023 09:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-first-occurrence-of-character-in-a-string/m-p/878924#M347261</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-06-02T09:41:00Z</dc:date>
    </item>
  </channel>
</rss>

