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
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;")
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;")
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.
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.