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;")
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.