BookmarkSubscribeRSS Feed
zoomzoom
Obsidian | Level 7

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?

 

 

 

 

3 REPLIES 3
ChrisNZ
Tourmaline | Level 20

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.

Quentin
Super User

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.
The Boston Area SAS Users Group is hosting free webinars!
Next up: Bart Jablonski and I present 53 (+3) ways to do a table lookup on Wednesday Sep 18.
Register now at https://www.basug.org/events.
zoomzoom
Obsidian | Level 7
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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1104 views
  • 2 likes
  • 3 in conversation