BookmarkSubscribeRSS Feed
NancyArora
Calcite | Level 5

I have a SQL Server Table with special character in its name. For eg: John&Smith_pvt. I want to fetch data from this table into a SAS data set using PROC SQL but I'm getting error and error states " ERROR: CLI describe error: [SAS][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Incorrect syntax near '&'. : [SAS][ODBC
SQL Server Wire Protocol driver][Microsoft SQL Server]Statement(s) could not be prepared."

 

Code I'm using:

 

proc sql;
connect to sqlsvr (dsn="John&Smith_pvt" user=&uid pass=&password);
CREATE TABLE Product AS
SELECT * FROM connection to sqlsvr
(select
SUM(UNITS) AS UNITS

from John&Smith_pvt

);

quit;

 

Solutions I've  tried:

 

1) %let tb_nm = %nrstr(John&Smith);, however macro variable %put &tb_nm is resolving correctly but it is not resolving again in my above mentioned table name.

 

2) I have also tried libname options, Preserve_tab_name = Yes . eg: libname abc sqlsvr dsn="ProductUnits" uid=&uid. pwd=&password schema= DBO; but no luck error is same as above mentioned.

 

Shout out to SAS expertise..!!

 

Could you please help me out in resolving this error?

 

Thank you in advance.

2 REPLIES 2
Kurt_Bremser
Super User

From https://docs.microsoft.com/en-us/sql/odbc/microsoft/table-name-limitations?view=sql-server-ver15 (first result of google search for "ms sql server valid table names"):

Table names can contain any valid characters (for example, spaces). If table names contain any characters except letters, numbers, and underscores, the name must be delimited by enclosing it in back quotes (`)

Tom
Super User Tom
Super User

Can you find the idiot that created DSN with an & in it and get them to change it something more user friendly?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 751 views
  • 0 likes
  • 3 in conversation