Hello,
There was an error massage on the Log window. Please help, thank you.
%macro covdate(regpronum,regprodate1);
%let i=(&rr + 1);
%let rr=%eval(&i);
proc sql;
create table cov&rr as
select studysite, scrdate, caseid, c_ageyears, c_agemonths, covidsource, ®pronum, ®prodate1
from ds2cov
where covidsource in(1,2,3) and ®pronum>=1 and ®pronum ^= 888 and ®prodate1 ^= '08aug8888'd
and ((®prodate1>"&bdate1."d or ®prodate1=.) or (c_ageyears>15 and ®prodate1<'12DEC2020'd) or
(12<=c_ageyears<=15 and ®prodate1<'12MAY2021'd) or (5<=c_ageyears<=11 and ®prodate1<'02NOV2021'd) or
(c_ageyears<5 and ®prodate1<'18JUN2022'd))
order by studysite,caseid;
%let cov_&rr=%str(®pronum. >=1 and not 888 while ®prodate1 may not be valid, please confirm);
ods proclabel "Check &rr:&&&cov_&rr";
data cov&rr;
length var1 $150;
set cov&rr;
var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))||','||
"dataset date="||trim(left(put("&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.)))||','||
"®pronum.="||trim(left(put(®pronum,3.)))||','||
"®prodate1.="||trim(left(put(®prodate1.,mmddyy10.)));
run;
%createcov;
%mend covdate;
%covdate(covnum,covdt1);
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 ((®prodate2
-
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>=2 and covnum
ne 888 and covdt2 ^= '08aug8888'd ((covdt2>"28FEB2023"d or covdt2=.) or (c_ageyears>15 and
covdt2<'12DEC2020'd) or (12<=c_ageyears<=15 and covdt2<'12MAY2021'd) or (5<=c_ageyears<=11 and
covdt2<'02NOV2021'd) or (c_ageyears<5 and covdt2<'18JUN2022'd))) order by studysite,caseid;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =,
>, >=, 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: && resolves to &.
SYMBOLGEN: Unable to resolve the macro variable reference &cov_
SYMBOLGEN: && resolves to &.
SYMBOLGEN: Macro variable RR resolves to 8
SYMBOLGEN: Macro variable COV_8 resolves to covnum >=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 >=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
There is no operator between these two expressions.
covdt2 ^= '08aug8888'd ((covdt2>"28FEB2023"d or covdt2=.)
There is no operator between these two expressions.
covdt2 ^= '08aug8888'd ((covdt2>"28FEB2023"d or covdt2=.)
Are you sure you ran the version of the macro you posted?
When I run it it does not generate code that is missing an operator nor does it have the extra closing parenthesis.
What your posted macro produces:
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>=1
and covnum ^= 888
and covdt1 ^= '08aug8888'd
and ((covdt1>"&bdate1."d or covdt1=.)
or (c_ageyears>15 and covdt1<'12DEC2020'd)
or (12<=c_ageyears<=15 and covdt1<'12MAY2021'd)
or (5<=c_ageyears<=11 and covdt1<'02NOV2021'd)
or (c_ageyears<5 and covdt1<'18JUN2022'd)
)
order by studysite,caseid;
What your SAS log shows as being produced
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>=2
and covnum ne 888
and covdt2 ^= '08aug8888'd
((covdt2>"28FEB2023"d or covdt2=.)
or (c_ageyears>15 and covdt2<'12DEC2020'd)
or (12<=c_ageyears<=15 and covdt2<'12MAY2021'd)
or (5<=c_ageyears<=11 and covdt2<'02NOV2021'd)
or (c_ageyears<5 and covdt2<'18JUN2022'd)
)
) order by studysite,caseid
;
You can simplify some of this
var1="scrdate="||trim(left(put(scrdate,mmddyy10.)))||','||
"dataset date="||trim(left(put("&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.)))||','||
"®pronum.="||trim(left(put(®pronum,3.)))||','||
"®prodate1.="||trim(left(put(®prodate1.,mmddyy10.)));
run;
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.
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.
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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.