SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
EbethF
Fluorite | Level 6

hello, I am struggling with syntax for my PROC SQL statement. I am pulling data from a very large database table from an ODBC link, and want to specify records based on the first two letters of a text field.

PROC SQL;

     CONNECT TO ODBC (DSN='CFD' USER=sa PWD=Password);

     CREATE TABLE SRORD_DETAIL AS SELECT * FROM CONNECTION TO ODBC (select SRORD_DET_ID,SRORDER_ID,LINE_NUMBER,

PROD_ID, PACKSIZE_ID, QTTY_ORDERED, COMMENT,

CUSTOMER_KEY

 

FROM SRORD_DETAIL

where CUSTOMER_KEY CONTAINS ‘OR’ );

    

    QUIT;

 

I can't seem to make the last WHERE statement work for syntax, I get this error:

ERROR: CLI describe error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'CONTAINS'. :

       [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.

(example of a record I want to keep in the image attached.)

 

help appreciated!srord.JPG

1 ACCEPTED SOLUTION

Accepted Solutions
EbethF
Fluorite | Level 6

thanks to both of you, a hybrid of those hints worked with this:

PROC SQL;

CONNECT TO ODBC (DSN='CFD' USER=sa PWD=Password);

CREATE TABLE SRORD_DETAIL AS SELECT * FROM CONNECTION TO ODBC(select SRORD_DET_ID,SRORDER_ID,LINE_NUMBER,

 

PROD_ID,

PACKSIZE_ID,

QTTY_ORDERED,

COMMENT,

CUSTOMER_KEY

from srord_detail

WHERE CUSTOMER_KEY LIKE ('OR%'));

 

 

 

QUIT;

 

View solution in original post

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

Did you try where CUSTOMER_KEY like 'OR%'

Thanks,
Suryakiran
PGStats
Opal | Level 21

Note:

 

select SRORD_DET_ID, SRORDER_ID, LINE_NUMBER, PROD_ID, PACKSIZE_ID, QTTY_ORDERED, COMMENT, CUSTOMER_KEY
FROM SRORD_DETAIL
where CUSTOMER_KEY CONTAINS ‘OR’

 

in your code is NOT a proc SQL query. It is a query that is transmitted by proc SQL to your SQL Server. It must obey the syntax rules of SQL Server.

PG
EbethF
Fluorite | Level 6
hmmm, okay. thank you for that.
EbethF
Fluorite | Level 6

thanks to both of you, a hybrid of those hints worked with this:

PROC SQL;

CONNECT TO ODBC (DSN='CFD' USER=sa PWD=Password);

CREATE TABLE SRORD_DETAIL AS SELECT * FROM CONNECTION TO ODBC(select SRORD_DET_ID,SRORDER_ID,LINE_NUMBER,

 

PROD_ID,

PACKSIZE_ID,

QTTY_ORDERED,

COMMENT,

CUSTOMER_KEY

from srord_detail

WHERE CUSTOMER_KEY LIKE ('OR%'));

 

 

 

QUIT;

 

s_lassen
Meteorite | Level 14

SQL Server does not have the CONTAINS operator like SAS SQL. To get the same result as with SAS "contains 'OR'" you will have to use "like '%OR%'". But it sounds like using "like 'OR%'" gives you what you want, so you should probably use that, as it is much faster.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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