vbala2014
vbala2014

Reputation: 161

SAS - using lib names declared in another file

I am new to SAS and am not sure if this is possible, currently I have a list of libnames that i have declared in my SAS code for my SAS code to work with. See below

%macro libs;
libname lib1 ODBC DATASRC=XXX schema=YYY USER=&uid1 PWD=&pwd1;
libname lib2 ODBC DATASRC=XXX schema=YYY USER=&uid2 PWD=&pwd2;
libname lib3 ODBC DATASRC=XXX schema=YYY USER=&uid3 PWD=&pwd3;
%mend;
%libs

I source the user name and password from an external file using the below code

data input_uid_pwd;
infile '/data/mytestfolder/scenarios/pgms/uidpwd.txt' dlm=',' firstobs=4;
input uid1: $30. pwd1: $30. uid2: $30. pwd2: $30. uid3: $30. pwd3: $30.;

call symputx('uid1', put(uid1, $30.), G);
call symputx('pwd1', put(pwd1, $30.), G);
call symputx('uid2', put(uid2, $30.), G);
call symputx('pwd2', put(pwd2, $30.), G);
call symputx('uid3', put(uid3, $30.), G);
call symputx('pwd3', put(pwd3, $30.), G);
run;

I was wondering if it is in any way possible to move the entire Libname macro and the data step outside of the current SAS code and reference it from another file. Is such a thing doable? or am I day dreaming here :) please let me know when you get a moment.

Upvotes: 2

Views: 127

Answers (1)

mjsqu
mjsqu

Reputation: 5452

Put the libname statements into another file and call it in your main SAS program using:

%inc "/data/mytestfolder/scenarios/pgms/libs.sas";

(Change the file path to suit)

This will run the statements in the external file, and assign the libraries.

Upvotes: 2

Related Questions