<?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: Check for a string in the file name using macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730691#M227557</link>
    <description>&lt;P&gt;Here's another solution using regular expressions. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s solution is more concise and what I'd suggest given that mine may not be totally intuitive, but I think it's always helpful to see multiple solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, my solution assumes there's only one macro variable you're trying to parse. You'd need to provide another parameter/modify the macro if you have multiple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _aud_infile = IFK_GTR_TRN_1_6010_1_20210127T163229.cs;

%macro test (values);
/* If you find the pattern specified in the macro call below (prxmatch &amp;gt; 0), then load sashelp.cars where the make is Toyota */
%if %sysfunc(prxmatch("&amp;amp;values.", &amp;amp;_aud_infile.)) &amp;gt; 0 %then %do; /* notice that I have the values parameter in quotes. */
	data work.toyotas;
		set sashelp.cars (where = (make = "Toyota"));
	run;
%end;
/* If you don't find the pattern in the macro call below (prxmatch = 0), then load sashelp.cars where make isn't Toyota */
%else %do;
	data work.nontoyotas;
		set sashelp.cars (where = (make ^= "Toyota"));
	run;
%end;
%mend test;

options symbolgen; /* For debugging purposes */

/* You have to specify pipes (|) separating the values for the regular expression search */

%test(5601|6010|6020); /* Pattern exists in this set of values. Should load Toyotas. */
%test(9999|2222|2010); /* Pattern does not exist in this set of values. Should load non-Toyotas */
%test(9999|1111|6010); /* Pattern exists in this set of values. Should load Toyotas.*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Apr 2021 13:47:33 GMT</pubDate>
    <dc:creator>maguiremq</dc:creator>
    <dc:date>2021-04-01T13:47:33Z</dc:date>
    <item>
      <title>Check for a string in the file name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730664#M227548</link>
      <description>&lt;P&gt;I've the macro variable &lt;STRONG&gt;_aud_infile&lt;/STRONG&gt; and it resolves to IFK_GTR_TRN_1_6010_1_20210127T163229.csv. Now I want to scan the value of the macro variable to see if string contains 5601 or 6010 or 6020. If it matches then I want to do execuete some conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I;m getting the error as shown below although the string matches with the macro variable. Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;2407                     %if (%sysfunc(scan(&amp;amp;_aud_infile.,5,"_")) in ('5601','6010','6020')  %then %do;
ERROR: Macro keyword DO appears as text.
ERROR: A dummy macro will be compiled.&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 12:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730664#M227548</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2021-04-01T12:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a string in the file name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730667#M227549</link>
      <description>&lt;P&gt;Make sure you have the correct number of open and close parentheses, I don't think you do. Make sure they are in the right place.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Inside of %SYSFUNC, you do not put arguments to functions in quotes or double-quotes.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I don't think the operator IN works in macro expressions, instead you might want to use the %INM macro function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro inm(slist,s);
    /* SAS Macro %inm to see if &amp;amp;s is contained in a string or list &amp;amp;slist                 */
    /* Borrowed from https://groups.google.com/forum/#!topic/comp.soft-sys.sas/fWcSDgg11tE */
    %if %sysfunc(indexw(&amp;amp;slist,&amp;amp;s)) gt 0 %then 1 ;
    %else 0;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 12:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730667#M227549</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-01T12:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a string in the file name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730691#M227557</link>
      <description>&lt;P&gt;Here's another solution using regular expressions. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s solution is more concise and what I'd suggest given that mine may not be totally intuitive, but I think it's always helpful to see multiple solutions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, my solution assumes there's only one macro variable you're trying to parse. You'd need to provide another parameter/modify the macro if you have multiple.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _aud_infile = IFK_GTR_TRN_1_6010_1_20210127T163229.cs;

%macro test (values);
/* If you find the pattern specified in the macro call below (prxmatch &amp;gt; 0), then load sashelp.cars where the make is Toyota */
%if %sysfunc(prxmatch("&amp;amp;values.", &amp;amp;_aud_infile.)) &amp;gt; 0 %then %do; /* notice that I have the values parameter in quotes. */
	data work.toyotas;
		set sashelp.cars (where = (make = "Toyota"));
	run;
%end;
/* If you don't find the pattern in the macro call below (prxmatch = 0), then load sashelp.cars where make isn't Toyota */
%else %do;
	data work.nontoyotas;
		set sashelp.cars (where = (make ^= "Toyota"));
	run;
%end;
%mend test;

options symbolgen; /* For debugging purposes */

/* You have to specify pipes (|) separating the values for the regular expression search */

%test(5601|6010|6020); /* Pattern exists in this set of values. Should load Toyotas. */
%test(9999|2222|2010); /* Pattern does not exist in this set of values. Should load non-Toyotas */
%test(9999|1111|6010); /* Pattern exists in this set of values. Should load Toyotas.*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 13:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730691#M227557</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-04-01T13:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a string in the file name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730693#M227558</link>
      <description>&lt;P&gt;Why are you using %SYSFUNC() to call the data step function SCAN() instead of just using the built in macro function %SCAN()?&amp;nbsp; Why are you including double quote characters in the list of delimiters for the scan function?&amp;nbsp; Does the filename you are scanning includes the double quotes?&amp;nbsp; Why are you inserting single quote characters into the strings you are looking for?&amp;nbsp; I doubt that you filenames contain those single quote characters around the number strings you are looking for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test(mvar) /minoperator ;
%local i found;
%let found=0;
%do i=1 %to %sysfunc(countw(&amp;amp;mvar,_));
  %if %scan(&amp;amp;mvar,&amp;amp;i,_) in 5601 6010 6020 %then %let found=1;
%end;
%put &amp;amp;=found;
%mend test;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;640   %test(IFK_GTR_TRN_1_6010_1_20210127T163229.csv) ;
FOUND=1
641   %test(junk.csv) ;
FOUND=0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730693#M227558</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-01T14:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Check for a string in the file name using macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730706#M227563</link>
      <description>&lt;P&gt;Macro.&lt;/P&gt;
&lt;P&gt;Macro.&lt;/P&gt;
&lt;P&gt;Macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro processor is a PURE TEXT PROCESSOR and sees everything as text, so no quotes are needed. &lt;EM&gt;No quotes are needed.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Next, for the IN to work, the corresponding system option must be set. And the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p0pbehl7wj5sl4n1ov1ortnehtba.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt; for that (Maxim 1!) contains several examples for the use of macro IN to arrive at this solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options minoperator;

%let _aud_infile = IFK_GTR_TRN_1_6010_1_20210127T163229.csv;

%if %scan(&amp;amp;_aud_infile.,5,_) in 5601 6010 6020
%then %do;
  %put Yes!;
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 14:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-for-a-string-in-the-file-name-using-macro-variable/m-p/730706#M227563</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T14:17:56Z</dc:date>
    </item>
  </channel>
</rss>

