DATA Step, Macro, Functions and more

Macro error

Reply
Contributor
Posts: 39

Macro error

I am trying to write a program involving a macro, and it fails at a very initial stage.

 

Code:

options symbolgen mprint mlogic;

%let lib=aa_temp1;

%let dsname=Party_Details;

 

%macro test;

 

data test11;

set &lib..&dsname.; 

run;

 

%mend;

%test();

 

Error when executed:

 

SYMBOLGEN: Macro variable lib resolves to aa_temp1

SYMBOLGEN; Macro variable dsname resolves to Party_Details

 

data test11;  set &lib..&dsname.;  run;

                    ____

                     180

ERROR 180-322: Statement is not valid or used out of proper order.

MPRIINT(TEST): Set aa_temp1.Party_Details;

 

I have tried the dsname in Set as &dsname as well as &dsname. , and there is the same error. Tried searching for the error, and still not sure why this simple line generates error. What is that I am missing?

 

 

 

 

PROC Star
Posts: 1,760

Re: Macro error

[ Edited ]

Your code as shown works fine.

%let lib=sashelp;
%let dsname=class;
%macro test;
  data test11;
    set &lib..&dsname.; 
  run;
%mend;
%test;
MLOGIC(TEST):  Beginning execution.
MPRINT(TEST):   data test11;
SYMBOLGEN:  Macro variable LIB resolves to sashelp
SYMBOLGEN:  Macro variable DSNAME resolves to class
MPRINT(TEST):   set sashelp.class;
MPRINT(TEST):   run;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST11 has 19 observations and 5 variables.
NOTE: DATA statement used:
      real time           0.01 seconds
      cpu time            0.00 seconds


MLOGIC(TEST):  Ending execution.

I suspect you are doing something different and your macro values are quoted. Try using the %unquote() function.

PROC Star
Posts: 1,324

Re: Macro error

Yes, please double-check that the code you posted is the same as the code you submitted.

 

Note that your macro call %test() ;  has parentheses, even though the macro does not have any parameters.  This will create the error message you get, though not near the SET statement.  So @ChrisNZ's suggestion about possible macro quoting in your real code is a good one. 

 

WHen I run your code as is, I get below log:

26   %test();
MLOGIC(TEST):  Beginning execution.
MPRINT(TEST):   data test11;
SYMBOLGEN:  Macro variable LIB resolves to aa_temp1
SYMBOLGEN:  Macro variable DSNAME resolves to Party_Details
MPRINT(TEST):   set aa_temp1.Party_Details;
MPRINT(TEST):   run;

NOTE: There were 1 observations read from the data set AA_TEMP1.PARTY_DETAILS.
NOTE: The data set WORK.TEST11 has 1 observations and 1 variables.

MLOGIC(TEST):  Ending execution.
180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN
      where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
Contributor
Posts: 39

Re: Macro error

Quentin and Chris,

Thank you for your input. I have closed the session, reopened and executed the same code - and it works now. Atleast I have learnt something new from you two.
Ask a Question
Discussion stats
  • 3 replies
  • 205 views
  • 2 likes
  • 3 in conversation