Help using Base SAS procedures

sas7bdat file on local drive

Posts: 0

sas7bdat file on local drive


Is there any way I could use the filename and fileref to get the data stored on a local drive without having to use libname into sas?

eg. data location is


I tried using
filename finance 'C:\abb\sasfile.sas7bdat' ;

data readraw;
infile finance;

But this just creates a file with zero obs and zero vars.

Is there any method in fileref i could use in here?


Super Contributor
Super Contributor
Posts: 3,174

Re: sas7bdat file on local drive

What are you trying to accomplish? You are attempting to read a SAS (propietary format) database member/table as an external (non-SAS) file....for what purpose or objective?

Scott Barry
SBBWorks, Inc.
Posts: 8,744

Re: sas7bdat file on local drive

A FILENAME statement is designed to point to data files that are NOT SAS data sets. A file that you point to with a FILENAME statement is generally a non-proprietary, ASCII text file or "flat file" that you want to read with SAS INPUT and INFILE statements in order to turn the file from it's "flat" form into SAS dataset form.

A LIBNAME statement is designed to give you a naming method for SAS datasets that is somewhat platform independent. So on UNIX and WINDOWS, I might have the "SOMEDATA.SAS7BDAT" SAS dataset file in these locations:
UNIX: /usr/bin/sasczz/mydata/somedata.sas7bdat
WIN: c:\temp\somedata.sas7bdat

And so if I had the following LIBNAME statements on each system:
UNIX: libname perm '/usr/bin/sasczz/mydata/somedata.sas7bdat';
WIN: libname perm 'c:\temp\somedata.sas7bdat';

Then this program would work on EITHER platform -- as long as the correct LIBNAME statement was issued before I submitted the code:
data new;
set perm.somedata;

proc freq data=perm.somedata;
tables charvar;

However if you wanted to write a program that referenced the absolute operating filename and path, you can do so. Let's look at a WINDOWS example:
data new;
set 'c:\temp\somedata.sas7bdat';

proc print data='c:\temp\somedata.sas7bdat';

proc freq data='c:\temp\somedata.sas7bdat';
tables age;

However, the downside of this approach is that you will now have a program that can ONLY run on a WINDOWS platform and ONLY run when the data is exactly in this location. What if FRED, who also has a copy of SOMEDATA.SAS7BDAT, wants to borrow a copy of your program -- but he put his data in this location:

That means that he will not be able to use your program until ALL the path references are changed. Or, what if you are writing and testing a program on your local drive, but plan to deploy that program on a server where the SAS dataset is stored in a different location??? Again, you would have to change all the physical file references in the entire program, instead of just changing a single LIBNAME statement.

When you have an existing SAS dataset, you would never read it with an INFILE/INPUT statement. When you have a operating system file with the extension of SAS7BDAT, that file is a proprietary format SAS dataset and should be referenced in your program with a SET statement or a DATA= option, as shown in my code snippet. Is there a reason you do not want to use a LIBNAME statement????

Posts: 0

Re: sas7bdat file on local drive

Thanks all,

Cynthia. This is exactly what I wanted to do. Actually I am using enterprize guide where in user could select File throught the prompt and I can easily run sas codes without using the libname and stuff ...

Thank you.
Trusted Advisor
Posts: 2,113

Re: sas7bdat file on local drive


EGuide creates a LIBNAME behind the scenes for you. It is still using a LIBNAME, it is just hiding it from the user interface. You can check by looking at the log.

The problem that Cynthia mentioned about providing your program/project to Fred exists in EGuide just like in base SAS. LIBNAMEs make EGuide much more portable.

Doc Muhlbaier
Super Contributor
Super Contributor
Posts: 365

Re: sas7bdat file on local drive

Hello Lisa,

It is possible to create a libname pointing to your local computer. To do this you need your computer name in the network. Right click on My Computer -> Properties -> Computer Name and write the contents of the entry Full Computer Name. Then use it
in libname like this:

libname mylib "\\\C$\abb";

Pay attention that C: -> C$. This approach is valid for Windows XP.

Ask a Question
Discussion stats
  • 5 replies
  • 5 in conversation