<?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: Macro Syntax error? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861998#M340464</link>
    <description>&lt;P&gt;You can simplify some of this&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))||','||
     "dataset date="||trim(left(put("&amp;amp;bdate1"d,mmddyy10.)))||','||
     "c_ageyears="||trim(left(put(c_ageyears,3.)))||','||
	 "c_agemonths="||trim(left(put(c_agemonths,3.)))||','||
     "covidsource="||trim(left(put(covidsource,3.)))||','||
     "&amp;amp;regpronum.="||trim(left(put(&amp;amp;regpronum,3.)))||','||
	 "&amp;amp;regprodate1.="||trim(left(put(&amp;amp;regprodate1.,mmddyy10.)));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have valid dates as the source for a put with a date format like mmddyy10 there is no need for Trim or left as the result is always exactly 10 characters long and looks like 01/25/2023.&lt;/P&gt;
&lt;P&gt;For other puts you can eliminated the LEFT by either using STRIP instead of TRIM(left , which is what strip does-remove all leading and trailing blanks, or use the -L parameter for put such as put(c_ageyears,3. -L) which left justifies the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly are you using that result set with Var1 to do? About the only really valid bit I have ever seen for placing multiple variable values into a single variable like this is to create a tooltip text box in a graph or map though usually I would use more descriptive text than a raw variable name like "c_age_years" preferring something more like "Age in Years" as nicer text to read and helpful for the user.&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2023 18:51:34 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-03-02T18:51:34Z</dc:date>
    <item>
      <title>Macro Syntax error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861987#M340456</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There was an&amp;nbsp;error massage on the Log window.&amp;nbsp; Please help, thank you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro covdate(regpronum,regprodate1);
%let i=(&amp;amp;rr + 1);
%let rr=%eval(&amp;amp;i);
proc sql;
create table cov&amp;amp;rr as
select studysite, scrdate, caseid, c_ageyears, c_agemonths, covidsource, &amp;amp;regpronum, &amp;amp;regprodate1 
from ds2cov
where covidsource in(1,2,3) and &amp;amp;regpronum&amp;gt;=1 and &amp;amp;regpronum ^= 888 and &amp;amp;regprodate1 ^= '08aug8888'd
      and ((&amp;amp;regprodate1&amp;gt;"&amp;amp;bdate1."d or &amp;amp;regprodate1=.) or (c_ageyears&amp;gt;15 and &amp;amp;regprodate1&amp;lt;'12DEC2020'd) or 
      (12&amp;lt;=c_ageyears&amp;lt;=15 and &amp;amp;regprodate1&amp;lt;'12MAY2021'd) or (5&amp;lt;=c_ageyears&amp;lt;=11 and &amp;amp;regprodate1&amp;lt;'02NOV2021'd) or
	  (c_ageyears&amp;lt;5 and &amp;amp;regprodate1&amp;lt;'18JUN2022'd))
order by studysite,caseid;

%let cov_&amp;amp;rr=%str(&amp;amp;regpronum. &amp;gt;=1 and not 888 while &amp;amp;regprodate1 may not be valid, please confirm);
ods proclabel "Check &amp;amp;rr:&amp;amp;&amp;amp;&amp;amp;cov_&amp;amp;rr";

data cov&amp;amp;rr;
length var1 $150;
set cov&amp;amp;rr;
var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))||','||
     "dataset date="||trim(left(put("&amp;amp;bdate1"d,mmddyy10.)))||','||
     "c_ageyears="||trim(left(put(c_ageyears,3.)))||','||
	 "c_agemonths="||trim(left(put(c_agemonths,3.)))||','||
     "covidsource="||trim(left(put(covidsource,3.)))||','||
     "&amp;amp;regpronum.="||trim(left(put(&amp;amp;regpronum,3.)))||','||
	 "&amp;amp;regprodate1.="||trim(left(put(&amp;amp;regprodate1.,mmddyy10.)));
run;

%createcov;
%mend covdate;
%covdate(covnum,covdt1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;MPRINT(ARICOV):  ;
MLOGIC(COVDATE):  Beginning execution.
MLOGIC(COVDATE):  Parameter REGPRONUM has value covnum
MLOGIC(COVDATE):  Parameter REGPRODATE1 has value covdt1
MLOGIC(COVDATE):  Parameter REGPRODATE2 has value covdt2
MLOGIC(COVDATE):  %LET (variable name is I)
SYMBOLGEN:  Macro variable RR resolves to 7
MLOGIC(COVDATE):  %LET (variable name is RR)
SYMBOLGEN:  Macro variable I resolves to (7 + 1)
MPRINT(COVDATE):   proc sql;
SYMBOLGEN:  Macro variable RR resolves to 8
SYMBOLGEN:  Macro variable REGPRONUM resolves to covnum
SYMBOLGEN:  Macro variable REGPRODATE1 resolves to covdt1
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRONUM resolves to covnum
SYMBOLGEN:  Macro variable REGPRONUM resolves to covnum
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
NOTE: Line generated by the invoked macro "COVDATE".
2           ((&amp;amp;regprodate2
            -
            22
            76
SYMBOLGEN:  Macro variable BDATE1 resolves to 28FEB2023
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
MPRINT(COVDATE):   create table cov8 as select studysite,caseid,scrdate,c_ageyears, c_agemonths,
covidsource,covnum, covdt1, covdt2 from ds2cov where covidsource in(1,2,3) and covnum&amp;gt;=2 and covnum
ne 888 and covdt2 ^= '08aug8888'd ((covdt2&amp;gt;"28FEB2023"d or covdt2=.) or (c_ageyears&amp;gt;15 and
covdt2&amp;lt;'12DEC2020'd) or (12&amp;lt;=c_ageyears&amp;lt;=15 and covdt2&amp;lt;'12MAY2021'd) or (5&amp;lt;=c_ageyears&amp;lt;=11 and
covdt2&amp;lt;'02NOV2021'd) or (c_ageyears&amp;lt;5 and covdt2&amp;lt;'18JUN2022'd))) order by studysite,caseid;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &amp;amp;, *, **, +, -, /, &amp;lt;, &amp;lt;=, &amp;lt;&amp;gt;, =,
              &amp;gt;, &amp;gt;=, AND, EQ, EQT, GE, GET, GROUP, GT, GTT, HAVING, LE, LET, LT, LTT, NE, NET, OR,
              ORDER, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

SYMBOLGEN:  Macro variable RR resolves to 8
MLOGIC(COVDATE):  %LET (variable name is COV_8)
SYMBOLGEN:  Macro variable REGPRONUM resolves to covnum
SYMBOLGEN:  Macro variable REGPRODATE2 resolves to covdt2
SYMBOLGEN:  Macro variable RR resolves to 8
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Unable to resolve the macro variable reference &amp;amp;cov_
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable RR resolves to 8
SYMBOLGEN:  Macro variable COV_8 resolves to covnum &amp;gt;=2 not 888 while covdt2 may not be valid, please
            confirm
SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted
            for printing.
MPRINT(COVDATE):   ods proclabel "check 8:covnum &amp;gt;=2 not 888 while covdt2 may not be valid, please
confirm";
SYMBOLGEN:  Macro variable RR resolves to 8
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Thu, 02 Mar 2023 17:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861987#M340456</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2023-03-02T17:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Syntax error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861988#M340457</link>
      <description>&lt;P&gt;There is no operator between these two expressions.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;covdt2 ^= '08aug8888'd ((covdt2&amp;gt;"28FEB2023"d or covdt2=.)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2023 17:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861988#M340457</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-02T17:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Syntax error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861991#M340458</link>
      <description>&lt;P&gt;Are you sure you ran the version of the macro you posted?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run it it does not generate code that is missing an operator nor does it have the extra closing parenthesis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What your posted macro produces:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table cov1 as 
select studysite
, scrdate
, caseid
, c_ageyears
, c_agemonths
, covidsource
, covnum
, covdt1 
from ds2cov
 where covidsource in(1,2,3)
and covnum&amp;gt;=1
and covnum ^= 888
and covdt1 ^= '08aug8888'd      
and ((covdt1&amp;gt;"&amp;amp;bdate1."d or covdt1=.)
  or (c_ageyears&amp;gt;15  and covdt1&amp;lt;'12DEC2020'd)
  or  (12&amp;lt;=c_ageyears&amp;lt;=15 and covdt1&amp;lt;'12MAY2021'd)
  or (5&amp;lt;=c_ageyears&amp;lt;=11 and covdt1&amp;lt;'02NOV2021'd)
  or (c_ageyears&amp;lt;5 and covdt1&amp;lt;'18JUN2022'd)
 ) 
order by studysite,caseid; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What your SAS log shows as being produced&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table cov8 as 
select studysite
,caseid
,scrdate
,c_ageyears
, c_agemonths
,covidsource
,covnum
, covdt1
, covdt2 
from ds2cov 
where covidsource in(1,2,3)
and covnum&amp;gt;=2
and covnum ne 888
and covdt2 ^= '08aug8888'd
((covdt2&amp;gt;"28FEB2023"d or covdt2=.)
 or (c_ageyears&amp;gt;15 and covdt2&amp;lt;'12DEC2020'd)
 or (12&amp;lt;=c_ageyears&amp;lt;=15 and covdt2&amp;lt;'12MAY2021'd)
 or (5&amp;lt;=c_ageyears&amp;lt;=11 and covdt2&amp;lt;'02NOV2021'd)
 or (c_ageyears&amp;lt;5 and covdt2&amp;lt;'18JUN2022'd)
)
) order by studysite,caseid
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 18:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861991#M340458</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-02T18:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Syntax error?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861998#M340464</link>
      <description>&lt;P&gt;You can simplify some of this&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))||','||
     "dataset date="||trim(left(put("&amp;amp;bdate1"d,mmddyy10.)))||','||
     "c_ageyears="||trim(left(put(c_ageyears,3.)))||','||
	 "c_agemonths="||trim(left(put(c_agemonths,3.)))||','||
     "covidsource="||trim(left(put(covidsource,3.)))||','||
     "&amp;amp;regpronum.="||trim(left(put(&amp;amp;regpronum,3.)))||','||
	 "&amp;amp;regprodate1.="||trim(left(put(&amp;amp;regprodate1.,mmddyy10.)));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you have valid dates as the source for a put with a date format like mmddyy10 there is no need for Trim or left as the result is always exactly 10 characters long and looks like 01/25/2023.&lt;/P&gt;
&lt;P&gt;For other puts you can eliminated the LEFT by either using STRIP instead of TRIM(left , which is what strip does-remove all leading and trailing blanks, or use the -L parameter for put such as put(c_ageyears,3. -L) which left justifies the result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly are you using that result set with Var1 to do? About the only really valid bit I have ever seen for placing multiple variable values into a single variable like this is to create a tooltip text box in a graph or map though usually I would use more descriptive text than a raw variable name like "c_age_years" preferring something more like "Age in Years" as nicer text to read and helpful for the user.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2023 18:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Syntax-error/m-p/861998#M340464</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-02T18:51:34Z</dc:date>
    </item>
  </channel>
</rss>

