<?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 findw erratic behavior in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276482#M55389</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro "isIn" which is supposed to test if&amp;nbsp; an element is in a given (macro) string.&lt;/P&gt;
&lt;P&gt;The code is as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro rank(string,element,sep=);
    /* Returns element's index in a list of elements */
    %if &amp;amp;sep ne %then %do;
        %sysfunc(findw(&amp;amp;chaine.,&amp;amp;element.,&amp;amp;sep,E))
    %end;
    %else %do;
        %sysfunc(find(&amp;amp;chaine.,&amp;amp;element.))
    %end;
%mend;

%macro isIn(string,element);
    /* Tests whether an element is in a given string */ 
    %eval(%rank(&amp;amp;string.,&amp;amp;element.,sep=' ')&amp;gt;0)
%mend;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somewhere in the program, &amp;amp;mystring. is initialized to "U Z E" (without the quotes) and elsewhere the following test occur :&lt;/P&gt;
&lt;P&gt;%if %isIn(&amp;amp;mystring,U) %then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The test is expected to return 1 since "U" is in "U Z E".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Several execution of the program give different results for the above test, yet the input is always the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It shoudn't be too complicated to modify the code and avoid using the findw function but I am just wondering&lt;/P&gt;
&lt;P&gt;what is wrong exactly and why the macro behavior seems random.&lt;/P&gt;
&lt;P&gt;Do you see anything wrong with the above code ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We use SAS 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jun 2016 13:04:17 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2016-06-10T13:04:17Z</dc:date>
    <item>
      <title>findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276482#M55389</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a macro "isIn" which is supposed to test if&amp;nbsp; an element is in a given (macro) string.&lt;/P&gt;
&lt;P&gt;The code is as follows :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro rank(string,element,sep=);
    /* Returns element's index in a list of elements */
    %if &amp;amp;sep ne %then %do;
        %sysfunc(findw(&amp;amp;chaine.,&amp;amp;element.,&amp;amp;sep,E))
    %end;
    %else %do;
        %sysfunc(find(&amp;amp;chaine.,&amp;amp;element.))
    %end;
%mend;

%macro isIn(string,element);
    /* Tests whether an element is in a given string */ 
    %eval(%rank(&amp;amp;string.,&amp;amp;element.,sep=' ')&amp;gt;0)
%mend;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somewhere in the program, &amp;amp;mystring. is initialized to "U Z E" (without the quotes) and elsewhere the following test occur :&lt;/P&gt;
&lt;P&gt;%if %isIn(&amp;amp;mystring,U) %then ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The test is expected to return 1 since "U" is in "U Z E".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Several execution of the program give different results for the above test, yet the input is always the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It shoudn't be too complicated to modify the code and avoid using the findw function but I am just wondering&lt;/P&gt;
&lt;P&gt;what is wrong exactly and why the macro behavior seems random.&lt;/P&gt;
&lt;P&gt;Do you see anything wrong with the above code ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We use SAS 9.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 13:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276482#M55389</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-06-10T13:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276484#M55390</link>
      <description>&lt;P&gt;I have translated the given code from french to english and missed some elements.&lt;/P&gt;
&lt;P&gt;The first arguments to findw adn find should be &amp;amp;string. not &amp;amp;chaine.&lt;/P&gt;
&lt;P&gt;There is no such problem is the original source code.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 13:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276484#M55390</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-06-10T13:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276489#M55392</link>
      <description>&lt;P&gt;Sorry, I am going to have to ask, why? &amp;nbsp;All that macro code, which is nigh on impossible to read, is doing is this:&lt;/P&gt;
&lt;P&gt;if index(&lt;SPAN&gt;"U Z E","U")&amp;gt;0&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Macro language is not there as a replacement for Base SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 13:24:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276489#M55392</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-10T13:24:40Z</dc:date>
    </item>
    <item>
      <title>Re: findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276493#M55394</link>
      <description>&lt;P&gt;One suspect area: &amp;nbsp;switching from FINDW to FIND. &amp;nbsp;If the initial string is WU X E, the FIND function will find U, but the FINDW function will not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, the executions are almost certainly using FINDW, not FIND. &amp;nbsp;In macro language, this comparison is true:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if ' ' ne %then %do;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 14:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276493#M55394</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-10T14:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276502#M55399</link>
      <description>&lt;P&gt;RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your answer.&lt;/P&gt;
&lt;P&gt;The program in question is a stored process from a web application. The "U" is in fact the value of a macrovariable that results from the user's choices in a form. We use macro code to take users inputs into account and determine the actions to take. I was unaware of the index function so we could replace the test by :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%if %sysfunc(index(&amp;amp;string.,&amp;amp;element))&amp;gt;0 %then %do; ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will try this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yet, I am still wondering how this macro can give random results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jun 2016 13:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276502#M55399</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-06-10T13:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: findw erratic behavior</title>
      <link>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276516#M55404</link>
      <description>Thanks. Using findw is the goal here, the string always being "U Z E" in the execution context where the problem occur (the U is always isolated).&lt;BR /&gt;</description>
      <pubDate>Fri, 10 Jun 2016 14:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/findw-erratic-behavior/m-p/276516#M55404</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-06-10T14:43:26Z</dc:date>
    </item>
  </channel>
</rss>

