<?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: Required operator not found in expression error in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705428#M216407</link>
    <description>&lt;P&gt;From what you've posted, the only macro statements required in your code are the beginning %IF statement and the finishing %END statement. Everything else can stay exactly like your first non-macro example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir1=/var/data/server/files;
%if &amp;lt; condition &amp;gt; %then %do;&lt;BR /&gt;
/*get file details from dir1*/
data files;
fref = "DIR1";
if filename(fref,"&amp;amp;dir1.") = 0
then do;
  did = dopen(fref);
  if did ne 0
  then do;
    do i = 1 to dnum(did);
      name = dread(did,i);
      if upcase(scan(name,-1,".")) = "CSV" then output;
    end;
    did = dclose(did);
  end;
  rc = filename(fref);
end;
keep name;
run;

/*macro variables for digit value from each file*/
data _null_;
set files;
digits = scan(name,5,'_');
call symputx(cats("id",_n_),digits);
run;&lt;BR /&gt;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 12 Dec 2020 02:01:49 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2020-12-12T02:01:49Z</dc:date>
    <item>
      <title>Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705281#M216315</link>
      <description>&lt;P&gt;I've the below data step which is working fine. However when I tried to convert it into macros, it's not working as I got the error as 'ERROR: Required operator not found in expression: filename(fref,"&amp;amp;dir1.") = 0'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;PRE&gt;%let dir1=/var/data/server/files;

/*get file details from dir1*/
data files;
fref = "DIR1";
if filename(fref,"&amp;amp;dir1.") = 0
then do;
  did = dopen(fref);
  if did ne 0
  then do;
    do i = 1 to dnum(did);
      name = dread(did,i);
      if upcase(scan(name,-1,".")) = "CSV" then output;
    end;
    did = dclose(did);
  end;
  rc = filename(fref);
end;
keep name;
run;

/*macro variables for digit value from each file*/
data _null_;
set files;
digits = scan(name,5,'_');
call symputx(cats("id",_n_),digits);
run;


&lt;/PRE&gt;
&lt;P&gt;When I convert it into macros,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;
 %if &amp;lt;condition&amp;gt; %then %do;

    data files;
    fref = "DIR1";
    %if filename(fref,"&amp;amp;dir1.") = 0
    %then %do; 
    did = dopen(fref);
    %if did ne 0
    %then %do;
    %do i = 1 %to dnum(did);
    name = dread(did,i);
    %if upcase(scan(name,-1,".")) = "CSV" %then output;
    %end;
    did = dclose(did);
    %end;
    rc = filename(fref);
    %end;
    keep name;
     run;

    /*macro variables for digit value from each file*/
    data _null_;
    set files;
    digits = scan(name,5,'_');
    call symputx(cats("id",_n_),digits);
    run;

    %end;&lt;/PRE&gt;
&lt;P&gt;Once the macro version works, I want to add this portion in the existing macro program and so&amp;nbsp;I want the solution only in macro.&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Log:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;SYMBOLGEN:  Macro variable DIR1 resolves to /var/data/server/files
ERROR: Required operator not found in expression: filename(fref,"&amp;amp;dir1.") = 0 &lt;/PRE&gt;
&lt;P&gt;Any help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 11:07:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705281#M216315</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-12-11T11:07:06Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705285#M216317</link>
      <description>&lt;P&gt;You replaced the &lt;STRONG&gt;IF&lt;/STRONG&gt; into &lt;STRONG&gt;%IF&lt;/STRONG&gt;, in that case sas expects to find a macro variable like &lt;STRONG&gt;&amp;amp;&lt;/STRONG&gt;xxx following the %IF.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To convert a sas code into macro you should convert it like in next example:&lt;/P&gt;
&lt;P&gt;suppose your code is:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
       if var = 1234 then do ; .... end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then while converting it to macro you need to choose what objects should be supplied&lt;/P&gt;
&lt;P&gt;(a dataset name, a variable name, a variable value, part of a statement etc.);&lt;/P&gt;
&lt;P&gt;You don't convert IF into %IF.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro doit(input, value);
    data want;
      set &amp;amp;input;
           if var = &amp;amp;value then do ; .... end;
    run;
%mend doit;
%doit(have,1234);&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 11:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705285#M216317</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-11T11:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705289#M216320</link>
      <description>&lt;P&gt;Can't we convert my code without parameters? My dataset code is different than in your example as I can't pass the value to the Parameters like you shown. I would like to know how to convert my code as macro and without Parameters and any hardcoding like you shown in your example.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 11:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705289#M216320</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-12-11T11:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705292#M216322</link>
      <description>&lt;P&gt;There are so many conceptual errors in your attempt to convert the data step into macro, i don't know where to start ...&lt;/P&gt;
&lt;P&gt;- all function calls that are part of macro-logic must be wrapped in %sysfunc&lt;/P&gt;
&lt;P&gt;- but: why do you changed the if-blocks to %if-blocks at all? you are still in a data step&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 12:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705292#M216322</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-11T12:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705296#M216323</link>
      <description>How to wrap with %sysfunc?&lt;BR /&gt;</description>
      <pubDate>Fri, 11 Dec 2020 13:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705296#M216323</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-12-11T13:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705306#M216326</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How to wrap with %sysfunc?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 1: Read the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=mcrolref&amp;amp;docsetTarget=p1o13d7wb2zfcnn19s5ssl2zdxvi.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Documentation&lt;/A&gt;. It provides the details, and lots of examples.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 14:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705306#M216326</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-11T14:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705309#M216329</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Filter-on-quarter-months-value-from-quarter-ending-date/m-p/704093#M215814" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Filter-on-quarter-months-value-from-quarter-ending-date/m-p/704093#M215814&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 14:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705309#M216329</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-12-11T14:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: Required operator not found in expression error in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705428#M216407</link>
      <description>&lt;P&gt;From what you've posted, the only macro statements required in your code are the beginning %IF statement and the finishing %END statement. Everything else can stay exactly like your first non-macro example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dir1=/var/data/server/files;
%if &amp;lt; condition &amp;gt; %then %do;&lt;BR /&gt;
/*get file details from dir1*/
data files;
fref = "DIR1";
if filename(fref,"&amp;amp;dir1.") = 0
then do;
  did = dopen(fref);
  if did ne 0
  then do;
    do i = 1 to dnum(did);
      name = dread(did,i);
      if upcase(scan(name,-1,".")) = "CSV" then output;
    end;
    did = dclose(did);
  end;
  rc = filename(fref);
end;
keep name;
run;

/*macro variables for digit value from each file*/
data _null_;
set files;
digits = scan(name,5,'_');
call symputx(cats("id",_n_),digits);
run;&lt;BR /&gt;
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Dec 2020 02:01:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Required-operator-not-found-in-expression-error-in-macro/m-p/705428#M216407</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-12T02:01:49Z</dc:date>
    </item>
  </channel>
</rss>

