BookmarkSubscribeRSS Feed
sg_kr
Obsidian | Level 7

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;

 

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sg_kr
Obsidian | Level 7

when i use agent_code in (&&A&x), i am getting the below error.

 

error.PNG


@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

 

gamotte
Rhodochrosite | Level 12

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

We cannot see what data you are running the code against, so no we cannot tell you what is wrong.

gamotte
Rhodochrosite | Level 12

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 ()".

Reeza
Super User

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 ()".


 

sg_kr
Obsidian | Level 7
here the full code:
/****************************************************************************************************/
/* 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;
Tom
Super User Tom
Super User

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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 948 views
  • 0 likes
  • 5 in conversation