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