BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
rs73
Calcite | Level 5

Hi,

 

I'm trying to automate my data sourcing based on who is logged on at the moment (providing the logged on user has proper access permission to the DB server). The MyODBC connection in the sample below is an ODBC connection setup in the computer, with windows active directory userid login is the only one required to connect to the server. No individual user password is required as it's all based on group policy.

 

I'm currently using the following connection script in SAS program:

 

%let MyDatasrc=connect to odbc as MyDataSrc (required="dsn=MyODBC;uid=myuserid");

---------------------------------------------------------------------------------------------------------------------

proc sql;

 

&MyDataSrc;

 

Create table MyData as
Select * From Connection to MyDataSrc (
Select Field1, Field2
From SANDPIT.dbo.MyData
);

 

disconnect from MyDataSrc;

quit;

----------------------------------------------------------------------------------------

 

How do I replace "myuserid" with something like &SYSUSERID system variable that get the user.

Seems like if I change the part that defines the odbc connection:

(required="dsn=MyODBC;uid=myuserid"), SAS won't accept it as a valid option

 

Thank you

Rianto

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

What database are you connecting to? If it is SQL Server then you may be able to use Windows Authentication and avoid supplying a userid at all:

 

connect to odbc as MyDataSrc (required="dsn=MyODBC;Trusted_Connection=yes;")

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

What database are you connecting to? If it is SQL Server then you may be able to use Windows Authentication and avoid supplying a userid at all:

 

connect to odbc as MyDataSrc (required="dsn=MyODBC;Trusted_Connection=yes;")
rs73
Calcite | Level 5
Yes, it is SQL server and Windows Authentication. I've tried it and it works!

Thank's heaps...

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2 replies
  • 2334 views
  • 1 like
  • 2 in conversation