BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

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


'C:\abb\sasfile.sas7bdat'

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

data readraw;
infile finance;
run;

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

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

Thanks,

L
5 REPLIES 5
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
Cynthia_sas
SAS Super FREQ
Hi:
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:
[pre]
data new;
set perm.somedata;
run;

proc freq data=perm.somedata;
tables charvar;
run;
[/pre]

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:
[pre]
data new;
set 'c:\temp\somedata.sas7bdat';
run;

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

proc freq data='c:\temp\somedata.sas7bdat';
tables age;
run;
[/pre]

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:
c:\data\fred\test\somedata.sas7bdat


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????

cynthia
deleted_user
Not applicable
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.
Doc_Duke
Rhodochrosite | Level 12
Lisa,

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
Duke
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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.

Sincerely,
SPR

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 6478 views
  • 0 likes
  • 5 in conversation