I am using enterprise guide 8.2 and SAS 9.4
%MACRO cycle (name, mo);
proc sql;
create table &mo AS
select a.creditaccountid, b.statusreasoncode as src_&name, c.externalstatuscode as esc_&name
from newdw.factfinancialmonthly a left join newdw.dimstatusreason b ON a.dimstatusreasonid=b.dimstatusreasonid
left join newdw.dimexternalstatus c ON a.dimexternalstatusID=c.dimexternalstatusID
where reportingdate eq "&mo"d
and activeaccountindicator= 1;
QUIT;
%MEND;
%cycle ('jan22','31jan2022'd);
ERROR MESSAGE
'31jan2022'd
ERROR22-322: Syntax error, expecting one of the following: a name, a quoted string. ERROR 200-322: The symbol is not recognized and will be ignored.
The macro variable reference obviously did resolve. If it did not resolve then you would have seen &mo in the error message instead of the value of MO.
What is it you are trying to do?
What is the SAS code you are trying to use the macro to generate?
When you run a macro, all macro variables are replaced by their value. So your macro actually runs this code that I am showing you. This code must be legal valid working SAS code, and it is not.
proc sql;
create table '31jan2022'd AS
select a.creditaccountid, b.statusreasoncode as src_'jan22', c.externalstatuscode as esc_'jan22'
from newdw.factfinancialmonthly a left join newdw.dimstatusreason b ON a.dimstatusreasonid=b.dimstatusreasonid
left join newdw.dimexternalstatus c ON a.dimexternalstatusID=c.dimexternalstatusID
where reportingdate eq "'31jan2022'd"d
and activeaccountindicator= 1;
QUIT;
Can you see what the problem is here? What different parts of this code are not legal valid working SAS code? How would you fix it to make it legal valid working SAS code?
The macro variable reference obviously did resolve. If it did not resolve then you would have seen &mo in the error message instead of the value of MO.
What is it you are trying to do?
What is the SAS code you are trying to use the macro to generate?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.