BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

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, &regpronum, &regprodate1 
from ds2cov
where covidsource in(1,2,3) and &regpronum>=1 and &regpronum ^= 888 and &regprodate1 ^= '08aug8888'd
      and ((&regprodate1>"&bdate1."d or &regprodate1=.) or (c_ageyears>15 and &regprodate1<'12DEC2020'd) or 
      (12<=c_ageyears<=15 and &regprodate1<'12MAY2021'd) or (5<=c_ageyears<=11 and &regprodate1<'02NOV2021'd) or
	  (c_ageyears<5 and &regprodate1<'18JUN2022'd))
order by studysite,caseid;

%let cov_&rr=%str(&regpronum. >=1 and not 888 while &regprodate1 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.)))||','||
     "&regpronum.="||trim(left(put(&regpronum,3.)))||','||
	 "&regprodate1.="||trim(left(put(&regprodate1.,mmddyy10.)));
run;

%createcov;
%mend covdate;
%covdate(covnum,covdt1);
Spoiler

 

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           ((&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>=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
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

There is no operator between these two expressions.

covdt2 ^= '08aug8888'd ((covdt2>"28FEB2023"d or covdt2=.)

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

There is no operator between these two expressions.

covdt2 ^= '08aug8888'd ((covdt2>"28FEB2023"d or covdt2=.)
Tom
Super User Tom
Super User

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
;

 

ballardw
Super User

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.)))||','||
     "&regpronum.="||trim(left(put(&regpronum,3.)))||','||
	 "&regprodate1.="||trim(left(put(&regprodate1.,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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 312 views
  • 2 likes
  • 3 in conversation