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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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