BookmarkSubscribeRSS Feed
shymaa
Calcite | Level 5

Hello, 

 

I created ODBC connection from Startthen selectControl Panel then selectSystem and Securitythen selectAdministrative Toolsthen selectData Sources (ODBC).

In SAS code i created the connection as follow: 

proc sql;

connect to odbc as mydb (dsn=&dsn);

execute
(set nocount on) by mydb;

 

i need to check if mydb object is actually connected to DB or not. so please help me to implement this in SAS 

 

i think it will be like that: 

if not mydb then  -- if the connection isn't created, then create the connection

    proc sql;

    connect to odbc as mydb (dsn=&dsn);

    execute
    (set nocount on) by mydb;

endif 

 

4 REPLIES 4
SASKiwi
PROC Star

An ODBC connection in SAS SQL only lasts as long as the SQL step boundary (the QUIT statement or another DATA or PROC statement) then it is automatically disconnected. Why do you want to check your connection? If it doesn't work then you get appropriate messages in your SAS log. 

 

proc sql
  connect to ODBC as mydb (....); <== creates connection

  SQL statements

quit; <== removes connection

 

 

shymaa
Calcite | Level 5

Hi SASkiwi

 

 

 

 

 

thanks, 

ballardw
Super User

You should be able to assign a library to the odbc connection and then use any of the SAS tools for examining the contents of the library.

 

Something like:

libname test odbc noprompt="dsn=&dsn";

 

If the library gets assigned you should see data there.

 

Ksharp
Super User

Check function libname() or libref()  .

 

%if (%sysfunc(libref(sashelp))) %then %put ERROR ;

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
  • 2274 views
  • 0 likes
  • 4 in conversation