BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Roundboy1
Calcite | Level 5

Hi All,

I'm new to SAS so apologies for the basic, "numpty" question but I get the above message from the below code:


{Editors Note: Reformatted for clarification)

BASEL_VEHICLE_EXTRACT.contract_type_id IN
58 ! (2,6,7,9,11,12,14,16,18-30,36,40-53,55-59,64,65,68,70-73,75,76,80,86,91-97,103,104,105,108,113-119,121-124,126,134,135)
59 and month(datepart(&run_date.)) = month(datepart(BASEL_VEHICLE_EXTRACT.TRANSACTION_DTTM))
_
22
WARNING: Apparent symbolic reference RUN_DATE not resolved.
59 and month(datepart(&run_date.)) = month(datepart(BASEL_VEHICLE_EXTRACT.TRANSACTION_DTTM))
_
22
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, ), BTRIM, INPUT, PUT, SUBSTRING, USER.
ERROR 22-322: Syntax error, expecting one of the following: a name, *

Any help would be greatly appreciated

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The macro variable run_date has never been defined in the session you are running that code in, hence you get the warning:

WARNING: Apparent symbolic reference RUN_DATE not resolved.

 

Not sure what else we can say?

[Editor's Note - Combined a couple of replies for completeness]

The error below indicates that the macro variable run_date has not been defined:

WARNING: Apparent symbolic reference RUN_DATE not resolved.

 

This issue results in the following error:

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, ), BTRIM, INPUT, PUT, SUBSTRING, USER.
ERROR 22-322: Syntax error, expecting one of the following: a name, *

 

This error occurs because the DATEPART function is expecting a parameter that is a name, a quoted string, etc. and what is being passed. because the macro variable run_date is not defined, is:

datepart(&run_date.)

 

To aid with debugging macro related issues I recommend running the code with the following macro system options 

options mprint mlogic symbolgen ;

[Editor's Note End]

 

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

The macro variable run_date has never been defined in the session you are running that code in, hence you get the warning:

WARNING: Apparent symbolic reference RUN_DATE not resolved.

 

Not sure what else we can say?

[Editor's Note - Combined a couple of replies for completeness]

The error below indicates that the macro variable run_date has not been defined:

WARNING: Apparent symbolic reference RUN_DATE not resolved.

 

This issue results in the following error:

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant, a missing value, ), BTRIM, INPUT, PUT, SUBSTRING, USER.
ERROR 22-322: Syntax error, expecting one of the following: a name, *

 

This error occurs because the DATEPART function is expecting a parameter that is a name, a quoted string, etc. and what is being passed. because the macro variable run_date is not defined, is:

datepart(&run_date.)

 

To aid with debugging macro related issues I recommend running the code with the following macro system options 

options mprint mlogic symbolgen ;

[Editor's Note End]

 

Roundboy1
Calcite | Level 5

RW9: Many thanks for the speedy reply. That is for the warning message? What about the actual error 22 message itself?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

That is also to do with the run_date being missing.  Macro is just a find an replace system, so look at the code which is generated:

and month(datepart()) = month(datepart(...

As you can see, nothing in datepart() call = error.

Kurt_Bremser
Super User

@Roundboy1 wrote:

RW9: Many thanks for the speedy reply. That is for the warning message? What about the actual error 22 message itself?


That's a consequence of the fact that the WARNING is about. Fix the missing macro variable problem, and the syntax ERROR will go away.

 

What happens: The macro preprocessor can't resolve &run_date., so it assumes it might just be code anyway, and leaves it untouched while delivering a WARNING. The text &run_date. is not what the data step compiler expects as an argument for datepart() (which must either be a constant or a valid numerical expression), and issues an ERROR.

 

Rule-of-thumb for debugging: fix code from the top of the log down. Never start with trying to fix the last ERROR/WARNING first.

s_lassen
Meteorite | Level 14

If this is SAS code for a where clause, you may also have another problem.

 

Using e.g. "contract_type in(36,40-53)" will not generate an error, but: SAS interpretes this as "contract_type in(36,40,-53)" which is probably not what you want. If this is SQL code that you are submitting to some database as passthrough, it might work. In that case you should check the documentation for the database.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 44907 views
  • 0 likes
  • 4 in conversation