- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I created ODBC connection from StartControl Panel
System and Security
Administrative Tools
Data 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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi SASkiwi,
Thanks for your help 🙂
yes, i found that sometimes the connection isn't created and the below line write in CSV file which contains the statistical result.
Line: connect to odbc as mydb (dsn=&dsn)
so i need to put the connection in for loop and it will end once the connection is created something like that
do i=1 to 5;
if connect to odbc as mydb (dsn=&dsn) then --> if the connection created
end;
else
i++;
End;
run;
thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Check function libname() or libref() .
%if (%sysfunc(libref(sashelp))) %then %put ERROR ;