<?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 need assistance making macro handle special characters in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/need-assistance-making-macro-handle-special-characters/m-p/528425#M5429</link>
    <description>&lt;P&gt;As part of a larger process, I need to scan a text file for a string. To do this, I'm using a macro I found online (sorry, can't remember where). I need assistance modifying it&amp;nbsp;so that the two parameters can contain special characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CheckFileForString(FilenameAndPath=,
                          SearchString=);
  %local SearchResult filrf rc fid c;
  %let SearchResult = 0; /* default unless the string is found */
  %let filrf=srcf;
  %let rc=%sysfunc(filename(filrf, &amp;amp;FilenameAndPath));
  %let fid=%sysfunc(fopen(&amp;amp;filrf));
  %if &amp;amp;fid &amp;gt; 0 %then %do;  /* if the file reference exists (can be opened) */
    %do %while(%sysfunc(fread(&amp;amp;fid))=0);  /* while file is still returning contents (until end) */
	                                      /* read portion of the file into the file data buffer */
	                                      /* the position of the file pointer is updated after the read */
	                                      /* operation so successive fread functions read successive file records */
      %let rc=%sysfunc(fget(&amp;amp;fid, charvar)); /* copy characters from file data buffer into a variable */
	                                         /* blanks are are implicit delimiters */

      %if %index(%superq(charvar), &amp;amp;SearchString) %then %do;/* test the character variable */  
	     %let SearchResult=1; /* set the return code */ 
		 %GOTO exit;
		                                                %end;
    %end;

	%exit:
    %let rc=%sysfunc(fclose(&amp;amp;fid));
  %end;
  %let rc=%sysfunc(filename(filrf));
  &amp;amp;SearchResult
%mend CheckFileForString;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...and here is an example which fails. In this case, I'm scanning a config file for a specific parameter. It happens to be in XML format but that's not something I need to concern myself with....I just need to see if it has the string somewhere.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET FILE_LOCATION = %STR(C:\Program Files (x86)\Program Name\file.with.multiple.periods);


%IF %CheckFileForString(FilenameAndPath = &amp;amp;FILE_LOCATION ,
                          SearchString = '&amp;lt;parameter&amp;gt;value&amp;lt;/parameter&amp;gt;') = 1 %THEN  

do something&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be appreciated!&lt;/P&gt;</description>
    <pubDate>Fri, 18 Jan 2019 19:21:22 GMT</pubDate>
    <dc:creator>desertsp2</dc:creator>
    <dc:date>2019-01-18T19:21:22Z</dc:date>
    <item>
      <title>need assistance making macro handle special characters</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-assistance-making-macro-handle-special-characters/m-p/528425#M5429</link>
      <description>&lt;P&gt;As part of a larger process, I need to scan a text file for a string. To do this, I'm using a macro I found online (sorry, can't remember where). I need assistance modifying it&amp;nbsp;so that the two parameters can contain special characters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the macro:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro CheckFileForString(FilenameAndPath=,
                          SearchString=);
  %local SearchResult filrf rc fid c;
  %let SearchResult = 0; /* default unless the string is found */
  %let filrf=srcf;
  %let rc=%sysfunc(filename(filrf, &amp;amp;FilenameAndPath));
  %let fid=%sysfunc(fopen(&amp;amp;filrf));
  %if &amp;amp;fid &amp;gt; 0 %then %do;  /* if the file reference exists (can be opened) */
    %do %while(%sysfunc(fread(&amp;amp;fid))=0);  /* while file is still returning contents (until end) */
	                                      /* read portion of the file into the file data buffer */
	                                      /* the position of the file pointer is updated after the read */
	                                      /* operation so successive fread functions read successive file records */
      %let rc=%sysfunc(fget(&amp;amp;fid, charvar)); /* copy characters from file data buffer into a variable */
	                                         /* blanks are are implicit delimiters */

      %if %index(%superq(charvar), &amp;amp;SearchString) %then %do;/* test the character variable */  
	     %let SearchResult=1; /* set the return code */ 
		 %GOTO exit;
		                                                %end;
    %end;

	%exit:
    %let rc=%sysfunc(fclose(&amp;amp;fid));
  %end;
  %let rc=%sysfunc(filename(filrf));
  &amp;amp;SearchResult
%mend CheckFileForString;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;...and here is an example which fails. In this case, I'm scanning a config file for a specific parameter. It happens to be in XML format but that's not something I need to concern myself with....I just need to see if it has the string somewhere.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET FILE_LOCATION = %STR(C:\Program Files (x86)\Program Name\file.with.multiple.periods);


%IF %CheckFileForString(FilenameAndPath = &amp;amp;FILE_LOCATION ,
                          SearchString = '&amp;lt;parameter&amp;gt;value&amp;lt;/parameter&amp;gt;') = 1 %THEN  

do something&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance would be appreciated!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 19:21:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-assistance-making-macro-handle-special-characters/m-p/528425#M5429</guid>
      <dc:creator>desertsp2</dc:creator>
      <dc:date>2019-01-18T19:21:22Z</dc:date>
    </item>
    <item>
      <title>Re: need assistance making macro handle special characters</title>
      <link>https://communities.sas.com/t5/New-SAS-User/need-assistance-making-macro-handle-special-characters/m-p/528440#M5430</link>
      <description>&lt;P&gt;The first suspicious piece is the quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%IF&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%CheckFileForString&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;FilenameAndPath &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;FILE_LOCATION &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;
                          SearchString &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;'&amp;lt;parameter&amp;gt;value&amp;lt;/parameter&amp;gt;'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%THEN&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would this work with no need to change the macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%IF&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%CheckFileForString&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;FilenameAndPath &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;FILE_LOCATION &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;
                          SearchString &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token string"&gt;&amp;lt;parameter&amp;gt;value&amp;lt;/parameter&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%THEN&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 19:59:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/need-assistance-making-macro-handle-special-characters/m-p/528440#M5430</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-18T19:59:03Z</dc:date>
    </item>
  </channel>
</rss>

