<?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: Concatenate multiple columns using catx and find position of a substring using findc in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917181#M361286</link>
    <description>&lt;P&gt;Why are you using FINDC, which is defined as (emphasis mine)&amp;nbsp;&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;P class="xis-shortDescription"&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;Searches a string for any character in a list of characters&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp;?&lt;/EM&gt;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;So in your case, you are effectively searching "D"&amp;nbsp; or "1"&amp;nbsp; (or "1" again and again).&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;I think you want FINDW&amp;nbsp; (find a word).&amp;nbsp; Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DEF3 = FINDW(catx(' ', of dec01-dec10),'D111');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;Edited addition:&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s response made me realize I should have added the following to this note.&amp;nbsp; The FINDW above returns the character position of the search string.&amp;nbsp; If, instead you actually want the word position, you need to add a 3rd and 4th parameter to the FINDW, as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DEF3 = FINDW(catx(' ', of dec01-dec10),'P102',' ','e');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;The 'e' 4th parameter says "count words instead of characters ...".&amp;nbsp; The 3rd parameter consequently becomes necessary to specify acceptable words boundaries.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;When the string is not found both versions of FINDW will return a zero.&amp;nbsp; But when it is found, you will see a difference.&amp;nbsp; And remember if some of the left-hand words are blank, those consecutive blanks will be seen as a single word separator.&lt;/P&gt;
&lt;/DIV&gt;</description>
    <pubDate>Wed, 21 Feb 2024 16:20:53 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-02-21T16:20:53Z</dc:date>
    <item>
      <title>Concatenate multiple columns using catx and find position of a substring using findc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917179#M361284</link>
      <description>&lt;P&gt;data your_dataset;&lt;BR /&gt;status = 'D';&lt;BR /&gt;dec01 = 'P101';&lt;BR /&gt;dec02 = 'P111';&lt;BR /&gt;dec03 = 'P102';&lt;BR /&gt;dec04 = '';&lt;BR /&gt;dec05 = '';&lt;BR /&gt;dec06 = '';&lt;/P&gt;&lt;P&gt;dec07 = '';&lt;BR /&gt;dec08 = '';&lt;BR /&gt;dec09 = '';&lt;BR /&gt;dec10 = '';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA your_dataset;&lt;BR /&gt;SET YOUR_DATASET;&lt;BR /&gt;DEF = catx(' ', of dec01-dec10) ;&lt;BR /&gt;DEF2 = FINDC(catx(' ', of dec01-dec10),'D111');&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally this should set value DEF2 to 0 as there is no D111 in the concatenated DEF. But SAS returns value of DEF2 as 2&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 15:50:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917179#M361284</guid>
      <dc:creator>ajatshatru</dc:creator>
      <dc:date>2024-02-21T15:50:54Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple columns using catx and find position of a substring using findc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917181#M361286</link>
      <description>&lt;P&gt;Why are you using FINDC, which is defined as (emphasis mine)&amp;nbsp;&lt;/P&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;P class="xis-shortDescription"&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;Searches a string for any character in a list of characters&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp;?&lt;/EM&gt;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;So in your case, you are effectively searching "D"&amp;nbsp; or "1"&amp;nbsp; (or "1" again and again).&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;I think you want FINDW&amp;nbsp; (find a word).&amp;nbsp; Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DEF3 = FINDW(catx(' ', of dec01-dec10),'D111');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;Edited addition:&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s response made me realize I should have added the following to this note.&amp;nbsp; The FINDW above returns the character position of the search string.&amp;nbsp; If, instead you actually want the word position, you need to add a 3rd and 4th parameter to the FINDW, as in&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DEF3 = FINDW(catx(' ', of dec01-dec10),'P102',' ','e');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P class="xis-shortDescription"&gt;The 'e' 4th parameter says "count words instead of characters ...".&amp;nbsp; The 3rd parameter consequently becomes necessary to specify acceptable words boundaries.&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-shortDescription"&gt;When the string is not found both versions of FINDW will return a zero.&amp;nbsp; But when it is found, you will see a difference.&amp;nbsp; And remember if some of the left-hand words are blank, those consecutive blanks will be seen as a single word separator.&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 21 Feb 2024 16:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917181#M361286</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-02-21T16:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple columns using catx and find position of a substring using findc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917182#M361287</link>
      <description>&lt;P&gt;FINDC() looks up characters not words/substrings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Searches a string for&lt;STRONG&gt; any character in a list of characters&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0jfvenvsqk24vn1q2ypospoq9ij.htm" target="_self"&gt;WHICHC()&lt;/A&gt; instead. FIND will return the character location not the index of the terms, so I think this is likely what you're after.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DEF2 = whichc('D111', of dec01-dec10);&lt;/CODE&gt;&lt;/PRE&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/463954"&gt;@ajatshatru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;data your_dataset;&lt;BR /&gt;status = 'D';&lt;BR /&gt;dec01 = 'P101';&lt;BR /&gt;dec02 = 'P111';&lt;BR /&gt;dec03 = 'P102';&lt;BR /&gt;dec04 = '';&lt;BR /&gt;dec05 = '';&lt;BR /&gt;dec06 = '';&lt;/P&gt;
&lt;P&gt;dec07 = '';&lt;BR /&gt;dec08 = '';&lt;BR /&gt;dec09 = '';&lt;BR /&gt;dec10 = '';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA your_dataset;&lt;BR /&gt;SET YOUR_DATASET;&lt;BR /&gt;DEF = catx(' ', of dec01-dec10) ;&lt;BR /&gt;DEF2 = FINDC(catx(' ', of dec01-dec10),'D111');&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally this should set value DEF2 to 0 as there is no D111 in the concatenated DEF. But SAS returns value of DEF2 as 2&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Feb 2024 16:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917182#M361287</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-02-21T16:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenate multiple columns using catx and find position of a substring using findc</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917187#M361289</link>
      <description>Thank you Reeza it will also work</description>
      <pubDate>Wed, 21 Feb 2024 16:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenate-multiple-columns-using-catx-and-find-position-of-a/m-p/917187#M361289</guid>
      <dc:creator>ajatshatru</dc:creator>
      <dc:date>2024-02-21T16:20:30Z</dc:date>
    </item>
  </channel>
</rss>

