Hi,
How can we read the SAS file along with the folder path?
Example:
/sas/abc/bcd/sasfile.sas7bdat
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.
You can see my topic here. At the end of the day, you must create or relate to a libref..
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;
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.
@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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.