BookmarkSubscribeRSS Feed
jcis7
Pyrite | Level 9

Hello!  The following code has an error. Can you help troubleshoot?

PROC SQL;



CREATE table Results AS



SELECT *



FROM ccall



WHERE (status='Reported'  AND  enrollment NE 0)



AND status='Not Reported' (WHERE code IN (SELECT number FROM DS));



QUIT;

I want to retain all that've reported with nonzero enrollment and all that've not reported that have codes located in a separate table named DS.... But I'm getting an error message below. Any help you can give is much appreciated!  Thanks!

__________________

LOG: 


73   PROC SQL;


74


75        CREATE table Results AS


76


77        SELECT *


78


79        FROM ccall


80


81        WHERE (status='Reported'  AND  enrollment NE 0)


82


83             AND status='Not Reported' (WHERE code IN (SELECT


                                                  -


                                                  22


                                                  76


83 ! number FROM dss));


ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <,


              <=, <>, =, >, >=, AND, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING,


              INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |,


              ||, ~, ~=.

4 REPLIES 4
Reeza
Super User

You can't have two where in the query, that should probably be an AND instead.

Also verify your brackets.

PGStats
Opal | Level 21

Try

PROC SQL;

CREATE table Results AS

SELECT *

FROM ccall

WHERE

     status = 'Reported'  AND 

     enrollment NE 0 AND

     status = 'Not Reported'  AND

     code IN (SELECT number FROM DS);

QUIT;

PG

PG
jcis7
Pyrite | Level 9

Thanks everyone! 

Vladislaff
SAS Employee

PROC SQL;

CREATE table Results AS

SELECT *

FROM ccall

WHERE

     (status = 'Reported'  AND

     enrollment NE 0) OR

     (status = 'Not Reported'  AND

     code IN (SELECT number FROM DS));

QUIT;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1557 views
  • 1 like
  • 4 in conversation