<?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: How to Find the Length of a numeric expression in a string which has also alphabetic character in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772365#M245240</link>
    <description>&lt;P&gt;If your want the length only, and not the product code, try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_b;
   set have;
   
   d = anydigit(product_definition);
   s = anyspace(product_definition, -1*d);
   e = anyspace(product_definition, d);
   code_length = e - s - 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the product code, too, just add substr using s as second parameter and code_length as third.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Oct 2021 07:47:00 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-10-06T07:47:00Z</dc:date>
    <item>
      <title>How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772181#M245161</link>
      <description>&lt;P&gt;I want to&amp;nbsp;Find the Length of a &lt;STRONG&gt;numeric expression in a string&amp;nbsp;which has also alphabetic character&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;For example i want to extract product code from &lt;STRONG&gt;product definition&lt;/STRONG&gt; and i need the length of it. My product definition is like this:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;"BRANDNAME YHR4084L NEW LINE SERIES TEA MACHINE"&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;from this i want the length of YHR4084L, so i need a function like anyalpha, or anydigit and i also need it to stop extracting rest of it.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;substr(product_definition,ANYDIGIT(PRODUCT_NAME)) as kod2&lt;/STRONG&gt;,&lt;/P&gt;
&lt;P&gt;when i use this code it extracts "&lt;STRONG&gt;4084L&amp;nbsp;NEW LINE SERIES TEA MACHINE" but i need&amp;nbsp;YHR4084L. And this product definitions vary so i need something that detects the end of mixed character (numeric expression in a string&amp;nbsp;which has also alphabetic character).&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 14:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772181#M245161</guid>
      <dc:creator>chinaski</dc:creator>
      <dc:date>2021-10-05T14:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772207#M245173</link>
      <description>&lt;P&gt;You can check each substring in the input string does it contains digits, something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to countw(&amp;lt;input string&amp;gt;);
  word = scan(&amp;lt;input string&amp;gt;,i);
  if compress(word,,'kd') ne ' ' then leave;
end;
putlog word=;
       &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Oct 2021 15:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772207#M245173</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-10-05T15:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772209#M245175</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135895"&gt;@chinaski&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to&amp;nbsp;Find the Length of a &lt;STRONG&gt;numeric expression in a string&amp;nbsp;which has also alphabetic character&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;For example i want to extract product code from &lt;STRONG&gt;product definition&lt;/STRONG&gt; and i need the length of it. My product definition is like this:&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;"BRANDNAME YHR4084L NEW LINE SERIES TEA MACHINE"&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;from this i want the length of YHR4084L, so i need a function like anyalpha, or anydigit and i also need it to stop extracting rest of it.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;substr(product_definition,ANYDIGIT(PRODUCT_NAME)) as kod2&lt;/STRONG&gt;,&lt;/P&gt;
&lt;P&gt;when i use this code it extracts "&lt;STRONG&gt;4084L&amp;nbsp;NEW LINE SERIES TEA MACHINE" but i need&amp;nbsp;YHR4084L. And this product definitions vary so i need something that detects the end of mixed character (numeric expression in a string&amp;nbsp;which has also alphabetic character).&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;H1 id="p0gq8bwobt4wjgn12km94wi66mxw" class="xis-title"&gt;&lt;A name="~1" target="_blank"&gt;&lt;/A&gt;&lt;FONT style="background-color: #fcdec0;"&gt;ANYDIGIT&lt;/FONT&gt; Function&lt;/H1&gt;
&lt;P class="xis-shortDescription"&gt;Searches a character string for a digit, and &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;returns the first position&lt;/STRONG&gt;&lt;/FONT&gt; at which the digit is found.&lt;/P&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which indicates that since your desired "word" does not &lt;STRONG&gt;start&lt;/STRONG&gt; with a digit that you want a different approach.&lt;/P&gt;
&lt;P&gt;If there is going to be only one of these words in a given entry then extract word by word and report the first with any digits. If there are multiples then you need to provide better examples and how we know which output you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One possible:&lt;/P&gt;
&lt;PRE&gt;data example;
   productname="BRANDNAME YHR4084L NEW LINE SERIES TEA MACHINE";
   do i=1 to countw(productname);
      if anydigit(scan(productname,i))&amp;gt;0 then do;
         kod2= scan(productname,i);
         leave;
      end;
   end;
   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;Make sure to define the length of your KOD2 variable before use.&lt;/P&gt;
&lt;P&gt;This finds and returns the first word with any digit in it. The LEAVE instruction says to quit the do loop when found (how the first if multiple words with digits exist).&lt;/P&gt;</description>
      <pubDate>Tue, 05 Oct 2021 15:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772209#M245175</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-05T15:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772365#M245240</link>
      <description>&lt;P&gt;If your want the length only, and not the product code, try:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want_b;
   set have;
   
   d = anydigit(product_definition);
   s = anyspace(product_definition, -1*d);
   e = anyspace(product_definition, d);
   code_length = e - s - 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the product code, too, just add substr using s as second parameter and code_length as third.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 07:47:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772365#M245240</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-06T07:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772366#M245241</link>
      <description>&lt;P&gt;I see an issue here that will come to bite you in your behind some time in the future.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt; "&lt;/SPAN&gt;&lt;STRONG&gt;4084L&amp;nbsp;NEW LINE SERIES TEA MACHINE"&amp;nbsp;&lt;/STRONG&gt;should be turned into&amp;nbsp;&lt;STRONG&gt;YHR4084L.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;But what if the manufacturer adds a code YMR4084L (or similar)? Or already has it?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 07:53:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772366#M245241</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-06T07:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to Find the Length of a numeric expression in a string which has also alphabetic character</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772389#M245254</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135895"&gt;@chinaski&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;"BRANDNAME YHR4084L NEW LINE SERIES TEA MACHINE"&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;In your real data can you define any pattern that would let us identify the product code in a string. Like: Is it always the 2nd word or does it always have 3 characters followed by some digits, ...or any other pattern.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just looking for digits might not work given that there are alphanumeric brand names like Toys4Kids, 3M, 7 Up, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 09:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-Find-the-Length-of-a-numeric-expression-in-a-string-which/m-p/772389#M245254</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-06T09:46:07Z</dc:date>
    </item>
  </channel>
</rss>

