<?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: %sysevalf error when counting words with %sysfunc(findw()) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452895#M283973</link>
    <description>&lt;P&gt;The problem is that for functions like FINDW()&amp;nbsp;that interpret the meaning of the parameters passed based on their type.&amp;nbsp; In macro code everything is a string.&amp;nbsp; So the %SYSFUNC() macro function tries to test whether the string being passed&amp;nbsp;should be considered&amp;nbsp;character or numeric.&amp;nbsp; It is that detection phase that is generating the error message.&amp;nbsp; It works when you use $ since then %SYSFUNC() has a easier time determining the type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s solution works because adding the single quote character to the list of delimiters also makes it easy for %SYSFUNC() to determine the type.&amp;nbsp; But it will change the result if the string being searched includes single quote characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changing the delimiter in the way you have should eliminate the issue.&amp;nbsp; You might want to use TRANSLATE() instead just in case the input string already has the $ character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = co$&amp;lt;figure&amp;gt;$untn hazardratio &amp;lt;figure&amp;gt; hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,%str( ),ei));
%put [&amp;amp;l_fign];

%let l_fign = %sysfunc(findw(%sysfunc(prxchange(s/\s+/\$/,-1,&amp;amp;columns)),&amp;lt;figure&amp;gt;,$,ei));
%put [&amp;amp;l_fign];

%let l_fign = %sysfunc(findw(%qsysfunc(translate(&amp;amp;columns,%str( $),%str($ ))),&amp;lt;figure&amp;gt;,$,ei));
%put [&amp;amp;l_fign];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will see that the version with the prxchange() function call finds the wrong location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Apr 2018 16:59:25 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-04-10T16:59:25Z</dc:date>
    <item>
      <title>%sysevalf error when counting words with %sysfunc(findw())</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452856#M283971</link>
      <description>&lt;P&gt;Can somebody please say what the problem is with this piece of code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = countn &amp;lt;figure&amp;gt; hazardratio hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,%str( ),ei));
%put [&amp;amp;l_fign];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem seems to lie with the space delimiter &lt;FONT face="courier new,courier"&gt;%str( )&lt;/FONT&gt;. It gives the right "answer" [2] but it also gives this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000" face="courier new,courier"&gt;ERROR: %SYSEVALF function has no expression to evaluate.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;(Interestingly, with this error present, some sql code further down in my macro simply fails to run, although it mprint-s.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the values in COLUMNS are, say, $-delimited, the problem goes away:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let l_fign = %sysfunc(findw(%sysfunc(prxchange(s/\s+/\$/,-1,&amp;amp;columns)),&amp;lt;figure&amp;gt;,$,ei));
%put [&amp;amp;l_fign];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;An explanation would be greatly appreciated, as would a suggestion as to how to get the code to run error-free with a space delimiter. I'm using SAS 9.4M3 on Linux X64.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 15:02:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452856#M283971</guid>
      <dc:creator>rhale</dc:creator>
      <dc:date>2018-04-10T15:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: %sysevalf error when counting words with %sysfunc(findw())</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452858#M283972</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = countn &amp;lt;figure&amp;gt; hazardratio hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,' ',ei));
%put [&amp;amp;l_fign];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Apr 2018 15:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452858#M283972</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-10T15:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: %sysevalf error when counting words with %sysfunc(findw())</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452895#M283973</link>
      <description>&lt;P&gt;The problem is that for functions like FINDW()&amp;nbsp;that interpret the meaning of the parameters passed based on their type.&amp;nbsp; In macro code everything is a string.&amp;nbsp; So the %SYSFUNC() macro function tries to test whether the string being passed&amp;nbsp;should be considered&amp;nbsp;character or numeric.&amp;nbsp; It is that detection phase that is generating the error message.&amp;nbsp; It works when you use $ since then %SYSFUNC() has a easier time determining the type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s solution works because adding the single quote character to the list of delimiters also makes it easy for %SYSFUNC() to determine the type.&amp;nbsp; But it will change the result if the string being searched includes single quote characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Changing the delimiter in the way you have should eliminate the issue.&amp;nbsp; You might want to use TRANSLATE() instead just in case the input string already has the $ character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = co$&amp;lt;figure&amp;gt;$untn hazardratio &amp;lt;figure&amp;gt; hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,%str( ),ei));
%put [&amp;amp;l_fign];

%let l_fign = %sysfunc(findw(%sysfunc(prxchange(s/\s+/\$/,-1,&amp;amp;columns)),&amp;lt;figure&amp;gt;,$,ei));
%put [&amp;amp;l_fign];

%let l_fign = %sysfunc(findw(%qsysfunc(translate(&amp;amp;columns,%str( $),%str($ ))),&amp;lt;figure&amp;gt;,$,ei));
%put [&amp;amp;l_fign];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You will see that the version with the prxchange() function call finds the wrong location.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Apr 2018 16:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/452895#M283973</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-04-10T16:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: %sysevalf error when counting words with %sysfunc(findw())</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/453129#M283974</link>
      <description>&lt;P&gt;Ah, thank you Reeza and Tom, that's very interesting. I think I can safely go with Reeza's solution because COLUMNS will always contain a pre-validated list of variable names plus &amp;lt;figure&amp;gt; somewhere in the list. Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 10:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/453129#M283974</guid>
      <dc:creator>rhale</dc:creator>
      <dc:date>2018-04-11T10:15:18Z</dc:date>
    </item>
    <item>
      <title>Re: %sysevalf error when counting words with %sysfunc(findw())</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/453450#M283975</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s answer could lead to thinking that empty strings are recognised by the macro language when&amp;nbsp;&amp;nbsp; '&amp;nbsp; ' &amp;nbsp; is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To remove any confusion, I'd rather add another delimiter like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = countn &amp;lt;figure&amp;gt; hazardratio hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,%str(~ ),ei));
%put [&amp;amp;l_fign];
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the following should remove any confusion for the macro parser as to what is where, but still generates the message somehow. Possibly a defect:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let columns = countn &amp;lt;figure&amp;gt; hazardratio hrlowercl hruppercl;
%let l_fign = %sysfunc(findw(&amp;amp;columns,&amp;lt;figure&amp;gt;,1,%str( ),ei));
%put [&amp;amp;l_fign];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 05:55:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sysevalf-error-when-counting-words-with-sysfunc-findw/m-p/453450#M283975</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-04-12T05:55:51Z</dc:date>
    </item>
  </channel>
</rss>

