hi,
when i run the below code, i have some syntax error.
please help me to compile them without error.
/****************************************************************************************************/
/* Check missing LOS 1 */
/****************************************************************************************************/
%macro Check_LOS;
%do x=1 %to &Month.;
data M&x;
set &FieldFileAppnd.;
if (month=(1+&x) and los=2);
run;
%create_list(M&x, agent_code, A&x, 2);
%put &&A.&x.;
proc print data=&FieldFileAppnd.; var agent_code club month los rank status; where agent_code in (&&A&x); run;
data L&x;
set &FieldFileAppnd.;
if agent_code in (&&A&x);
if month=&x and los=0;
run;
proc print data=L&x; var agent_code club month los rank status; run;
%end;
%mend;
%Check_LOS;
%macro LOS_Merge;
data LOS_Merge;
set %do x=1 %to &Month.; L&x %end;;
run;
/*%end;*/
%mend;
%LOS_Merge;
proc sort data=LOS_Merge; by agent_code month los; run;
proc print data=LOS_Merge; var agent_code club month los rank status; run;
/* Check missing LOS 1 - Join to Field File to pull other fields */
proc sql;
create table LOS_Check as
select a.agent_code, a.club, a.month, a.los, a.rank, a.status, b.agent_code
from &FieldFileAppnd. as a, LOS_Merge as b
where a.agent_code=b.agent_code;
quit;
proc sort data=LOS_Check; by agent_code month; run;
title1 'Check missing LOS 1';
proc print data=LOS_Check; run;
proc export data=LOS_Check
outfile="&Dir.\FFIssues"
dbms=xlsx replace;
run;
Error:
SYMBOLGEN: Macro variable X resolves to 8
NOTE 137-205: Line generated by the invoked macro "CHECK_LOS".
38 proc print data=&FieldFileAppnd.; var agent_code club month los rank status; where
38 ! agent_code in (&&A&x); run; data L&x; set &FieldFileAppnd.; if agent_code in
-
22
38 ! (&&A&x); if month=&x and los=0; run; proc print data=L&x; var agent_code club
ERROR 22-322: Syntax error, expecting one of the following: a quoted string,
a numeric constant, a datetime constant, a missing value.
NOTE: Line generated by the invoked macro "CHECK_LOS".
38 proc print data=&FieldFileAppnd.; var agent_code club month los rank status; where
38 ! agent_code in (&&A&x); run; data L&x; set &FieldFileAppnd.; if agent_code in
-
76
38 ! (&&A&x); if month=&x and los=0; run; proc print data=L&x; var agent_code club
ERROR 76-322: Syntax error, statement will be ignored.
SYMBOLGEN: Macro variable A8 resolves to
MPRINT(CHECK_LOS): where agent_code in ();
ERROR: Syntax error while parsing WHERE clause.
MPRINT(CHECK_LOS): run;
Macro variable A8 resolves to
MPRINT(CHECK_LOS): where agent_code in ();
Your problem is described there, there is no macro variable called A8 at that point, so the line generated: where agent_code in ();
is invalid. There is nothing to work with, no test data in the form of a datastep etc. to test anything.
As a tip though, if your writing code like: &&A&x
Then 100% there is a far better and simpler method of doing whatever it is you want to achieve.
when i use agent_code in (&&A&x), i am getting the below error.
@RW9 wrote:Macro variable A8 resolves to
MPRINT(CHECK_LOS): where agent_code in ();
Your problem is described there, there is no macro variable called A8 at that point, so the line generated: where agent_code in ();
is invalid. There is nothing to work with, no test data in the form of a datastep etc. to test anything.
As a tip though, if your writing code like: &&A&x
Then 100% there is a far better and simpler method of doing whatever it is you want to achieve.
@RW9 wrote:Macro variable A8 resolves to
MPRINT(CHECK_LOS): where agent_code in ();
Your problem is described there, there is no macro variable called A8 at that point, so the line generated: where agent_code in ();
is invalid. There is nothing to work with, no test data in the form of a datastep etc. to test anything.
As a tip though, if your writing code like: &&A&x
Then 100% there is a far better and simpler method of doing whatever it is you want to achieve.
i want to know why its hapening, can you please help
We can't help with the information you provided since the problem concerns a macrovariable, A8,
for which we have no idea of how it was created and what its purpose is.
Is it normal that A8 is blank ? What should be done in such case ? Only you know the answers.
We cannot see what data you are running the code against, so no we cannot tell you what is wrong.
Hello,
I have reformatted your code so that it is more readable :
/****************************************************************************************************/
/* Check missing LOS 1 */
/****************************************************************************************************/
%macro Check_LOS;
%do x=1 %to &Month.;
data M&x;
set &FieldFileAppnd.;
if (month=(1+&x) and los=2);
run;
%create_list(M&x, agent_code, A&x, 2);
proc print data=&FieldFileAppnd.;
var agent_code club month los rank status; where agent_code in (&&A&x);
run;
data L&x;
set &FieldFileAppnd.;
if agent_code in (&&A&x);
if month=&x and los=0;
run;
proc print data=L&x;
var agent_code club month los rank status;
run;
%end;
%mend;
%Check_LOS;
%macro LOS_Merge;
data LOS_Merge;
set %do x=1 %to &Month.; L&x %end;;
run;
%mend;
%LOS_Merge;
proc sort data=LOS_Merge; by agent_code month los; run;
proc print data=LOS_Merge;
var agent_code club month los rank status;
run;
/* Check missing LOS 1 - Join to Field File to pull other fields */
proc sql;
create table LOS_Check as
select a.agent_code, a.club, a.month, a.los, a.rank, a.status, b.agent_code
from &FieldFileAppnd. as a, LOS_Merge as b
where a.agent_code=b.agent_code;
quit;
proc sort data=LOS_Check; by agent_code month; run;
title1 'Check missing LOS 1';
proc print data=LOS_Check; run;
proc export data=LOS_Check
outfile="&Dir.\FFIssues"
dbms=xlsx replace;
run;
Since you don't provide data and some macrovariables/macro functions are not defined, it is impossible for us to
replicate your problem. From the log, macrovariable A8 resolves to an empty string resulting in
syntactically incorrect code such as "where agent_code in ()".
Is there a specific reason you're breaking your data into months like this?
There's probably a data step solution here without the need for any macro variables.
When you essentially do GROUP processing without a single BY statement that is flag that you're probably doing too much work to get the results you need.
Your code also calls another macro create_list that seems to generate the problematic macro variable. That may be the issue and we cannot see that code.
@gamotte wrote:
Hello,
I have reformatted your code so that it is more readable :
/****************************************************************************************************/ /* Check missing LOS 1 */ /****************************************************************************************************/ %macro Check_LOS; %do x=1 %to &Month.; data M&x; set &FieldFileAppnd.; if (month=(1+&x) and los=2); run; %create_list(M&x, agent_code, A&x, 2); proc print data=&FieldFileAppnd.; var agent_code club month los rank status; where agent_code in (&&A&x); run; data L&x; set &FieldFileAppnd.; if agent_code in (&&A&x); if month=&x and los=0; run; proc print data=L&x; var agent_code club month los rank status; run; %end; %mend; %Check_LOS; %macro LOS_Merge; data LOS_Merge; set %do x=1 %to &Month.; L&x %end;; run; %mend; %LOS_Merge; proc sort data=LOS_Merge; by agent_code month los; run; proc print data=LOS_Merge; var agent_code club month los rank status; run; /* Check missing LOS 1 - Join to Field File to pull other fields */ proc sql; create table LOS_Check as select a.agent_code, a.club, a.month, a.los, a.rank, a.status, b.agent_code from &FieldFileAppnd. as a, LOS_Merge as b where a.agent_code=b.agent_code; quit; proc sort data=LOS_Check; by agent_code month; run; title1 'Check missing LOS 1'; proc print data=LOS_Check; run; proc export data=LOS_Check outfile="&Dir.\FFIssues" dbms=xlsx replace; run;
Since you don't provide data and some macrovariables/macro functions are not defined, it is impossible for us to
replicate your problem. From the log, macrovariable A8 resolves to an empty string resulting in
syntactically incorrect code such as "where agent_code in ()".
If that is the full program you should be getting earlier error messages.
The first thing that code tries to run is the call to the macro CHECK_LOS. And the first thing that macro does is reference the macro variable MONTH.
But there is nothing in the code you posted to create the macro variable MONTH.
or FieldFileAppnd
or any dataset that might be named by the value in FieldFileAppnd, if it existed.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.