BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello Experts,

I'm wondering why I got this error using the list :

 

where datepart(a.ma_date) in (mdy(12,31,year(today())-1), mdy(12,31,year(today())-2), mdy(12,31,year(today())-3),
                                          ___
                                          79
                                          76
ERROR 79-322: Expecting a SELECT.

Thank you for your help !

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

The IN operator in SAS wants a list of VALUES, not function calls.

The IN operator in SQL also allows a subquery, hence the reference to a missing SELECT.

 

Examples:

 71         proc sql;
 72         select * from sashelp.class
 73         where age in (13)
 74         ;
 75         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.01 seconds
       cpu time            0.02 seconds
       
 
 76         proc sql;
 77         select * from sashelp.class
 78         where age in (130/10)
                             _
                             22
                             200
 ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, a missing value, ), ',', -, 
               :.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 79         ;
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 80         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 
 81         proc sql;
 82         select * from sashelp.class
 83         where age in (select age from sashelp.class where age=130/10)
 84         ;
 85         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds

Since your functions are not referencing anything that varies you could use the macro language to generate the date constants.

For example by using %SYSFUNC() to call the SAS functions.

where datepart(a.ma_date) in 
(%sysfunc(intnx(year,%sysfunc(today()),-1,e))
,%sysfunc(intnx(year,%sysfunc(today()),-2,e))
,%sysfunc(intnx(year,%sysfunc(today()),-3,e))
)   

Or just put the dates needed into a macro variable.

data _null_;
  length datelist $100;
  do offset=1 to 3 ;
    datelist=catx(' ',datelist,intnx('year',today(),-offset,'e'));
  end;
  call symputx('datelist',datelist);
run;
%put &=datelist;

...
where datepart(a.ma_date) in (&datelist)
...

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Please show us the FULL COMPLETE log for this PROC SQL.

 

In the future, please always (that's 100% of the time, don't wait for us to ask) show us the FULL COMPLETE log for any PROC that gives you an error.

--
Paige Miller
Tom
Super User Tom
Super User

The IN operator in SAS wants a list of VALUES, not function calls.

The IN operator in SQL also allows a subquery, hence the reference to a missing SELECT.

 

Examples:

 71         proc sql;
 72         select * from sashelp.class
 73         where age in (13)
 74         ;
 75         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.01 seconds
       cpu time            0.02 seconds
       
 
 76         proc sql;
 77         select * from sashelp.class
 78         where age in (130/10)
                             _
                             22
                             200
 ERROR 22-322: Syntax error, expecting one of the following: a numeric constant, a datetime constant, a missing value, ), ',', -, 
               :.  
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 79         ;
 NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
 80         quit;
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 
 81         proc sql;
 82         select * from sashelp.class
 83         where age in (select age from sashelp.class where age=130/10)
 84         ;
 85         quit;
 NOTE: PROCEDURE SQL used (Total process time):
       real time           0.01 seconds
       cpu time            0.01 seconds

Since your functions are not referencing anything that varies you could use the macro language to generate the date constants.

For example by using %SYSFUNC() to call the SAS functions.

where datepart(a.ma_date) in 
(%sysfunc(intnx(year,%sysfunc(today()),-1,e))
,%sysfunc(intnx(year,%sysfunc(today()),-2,e))
,%sysfunc(intnx(year,%sysfunc(today()),-3,e))
)   

Or just put the dates needed into a macro variable.

data _null_;
  length datelist $100;
  do offset=1 to 3 ;
    datelist=catx(' ',datelist,intnx('year',today(),-offset,'e'));
  end;
  call symputx('datelist',datelist);
run;
%put &=datelist;

...
where datepart(a.ma_date) in (&datelist)
...
SASdevAnneMarie
Barite | Level 11
Thank you Tom!
Amir
PROC Star

Hi,

 

It appears you are trying to specify date constants via the use of functions; the in operator documentation specifies:

 

constant

is a number or a quoted character string (or other special notation) that indicates a fixed value. Constants are also called literals.

 

so that is why there is an error when you use a function, as it is neither a "number or a quoted character string", even though it returns a number.

 

 

Thanks & kind regards,

Amir.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

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
  • 4 replies
  • 185 views
  • 4 likes
  • 4 in conversation