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-2024.png

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.

 

Register now!

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
  • 810 views
  • 2 likes
  • 4 in conversation