I am wondering if there is a way to pull the name of the file defined in the LIBNAME statement into a variable.
That is, is there an analog to the FILENAME= option of the INFILE statement for the SET statement?
I would like to be able to access the name of the file to place it in report titles.
Thanks.
you can extract pathnames from dictionary.members or by using pathname function. Need to use capital letters while using dictionary.members. replace yourlib with libname
proc sql ;
select distinct path as path_var from dictionary.members
where libname= 'YOURLIB';
data abc;
path_var=pathname('yourlib');
run;
The SET statement supports the INDSNAME= option. That should be a possibility.
looks like you have by mistakenly, selected my answer as accepted answer instead of @Astounding answer
You could easily have been right ... I wasn't sure what the end goal was either.
At any rate, use the SCAN function to pick out the second part of the name returned by INDSNAME=:
member_name = scan(full_name, 2, '.');
I found that this worked when using a file on the SAS server.
What I failed to mention was that I was using the code while connected to the mainframe. When connected to the mainframe, it is necessary to use the PROC SQL answer of kirnav_.
you can extract pathnames from dictionary.members or by using pathname function. Need to use capital letters while using dictionary.members. replace yourlib with libname
proc sql ;
select distinct path as path_var from dictionary.members
where libname= 'YOURLIB';
data abc;
path_var=pathname('yourlib');
run;
The PATHNAME() function will return the path that a libref or fileref is using.
You can use it in a data step.
data _null_;
length path $256 ;
path=pathname('mylib');
put path= ;
run;
Or wrap it in %SYSFUNC() and use it directly in macro code.
%let path=%sysfunc(pathname(mylib));
You can also ask PROC CONTENTS to tell you where a particular dataset is. That is useful if you libref is actually pointing to multiple directories.
proc contents data=mylib.mymember;
run;
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.