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
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]
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]
RW9: Many thanks for the speedy reply. That is for the warning message? What about the actual error 22 message itself?
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.
@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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.