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

Hi, 

 

How can we read the SAS file along with the folder path?

 

Example:

 

/sas/abc/bcd/sasfile.sas7bdat

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

See this:

data "/folders/myfolders/class.sas7bdat";
set sashelp.class;
run;

data class;
set "/folders/myfolders/class.sas7bdat";
run;

libname myfold '/folders/myfolders';

data class;
set myfold.class;
run;

The preferred method is always to use a defined LIBNAME.

View solution in original post

3 REPLIES 3
Phil_NZ
Barite | Level 11

You can see my topic here. At the end of the day, you must create or relate to a libref..

 

https://communities.sas.com/t5/SAS-Programming/How-to-call-a-sas7bdat-file-directly-without-referrin...

 

So I will suggest it is a good idea to refer to a directory rather than the file physically itself per se.

 

As @Tom  said:


You can use the same syntax with any other place where you would reference a dataset.

proc means data="C:\downloads\class"; run;

Notice that under the hood SAS will actually create a libref that points to that directory. Example:

proc contents data="C:\downloads\class" out=contents; run;
proc print data=contents;
  var libname memname name type length ;
run;

Results:

Obs    LIBNAME     MEMNAME    NAME      TYPE    LENGTH

 1     WC000001     CLASS     Age         1        8
 2     WC000001     CLASS     Height      1        8
 3     WC000001     CLASS     Name        2        8
 4     WC000001     CLASS     Sex         2        1
 5     WC000001     CLASS     Weight      1        8

Now once you have referenced the file a specific libref will exist and you could use it to reference the dataset instead as long as you are in the same SAS session.

proc means data=WC000001.class; run;

But if you prefer to use the normal libname.memname syntax then it is better to write your own LIBNAME statement so that you have control over the libref that is used as there is not really anyway to know in advance what libref will be generated by using the quoted physical filename syntax.

 

So use something like this instead:

libname mydata "C:\downloads" ;
proc contents data=mydata.class; 
run;
proc means data=mydata.class;
run;

 

Thank you for your help, have a fabulous and productive day! I am a novice today, but someday when I accumulate enough knowledge, I can help others in my capacity.
Kurt_Bremser
Super User

See this:

data "/folders/myfolders/class.sas7bdat";
set sashelp.class;
run;

data class;
set "/folders/myfolders/class.sas7bdat";
run;

libname myfold '/folders/myfolders';

data class;
set myfold.class;
run;

The preferred method is always to use a defined LIBNAME.

andreas_lds
Jade | Level 19

@Kurt_Bremser wrote:
...

The preferred method is always to use a defined LIBNAME.


Just wanted to a minor emphasis on the preferred way to access datasets. @psrajput: Forget the other method, it will cause trouble sooner than one expects.

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
  • 3 replies
  • 8010 views
  • 0 likes
  • 4 in conversation