BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pplummer62
Fluorite | Level 6

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.

1 ACCEPTED SOLUTION

Accepted Solutions
kiranv_
Rhodochrosite | Level 12

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;

View solution in original post

7 REPLIES 7
pplummer62
Fluorite | Level 6
This almost does it.
If you have the statement LIBNAME FILEREF "SASDATASET; in your program

Then when you use this: SET FILEREF.SETNAME INDSNAME= DSNAME , the value of DSNAME is FILEREF.SETNAME when what I was wanting it to be equal to SASDATASET.
kiranv_
Rhodochrosite | Level 12

looks like you have by mistakenly, selected my answer as accepted answer instead of @Astounding answer

Astounding
PROC Star

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, '.');

pplummer62
Fluorite | Level 6

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

 

kiranv_
Rhodochrosite | Level 12

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;
Tom
Super User Tom
Super User

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1097 views
  • 2 likes
  • 4 in conversation