In SAS Programming 1: Essentials, lesson 2 I am prompted to write a proc to display contents.
I was unable to do this even after I was give the answer:
proc contents data="FILEPATH/storm_summary.sas7bdat"; run;
I didn't understand the FILEPATH.
After some searching in help I found that the correct syntax was:
Proc contents data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat";
run;
I understand the portion "/myfolders/WPG194/data/storm_summary.sas7bdat" but I don't understand "/folders"
because at that point it is really "/SASUniversityEdition". How can a literal "/folders" mean something other than what it says? I would expect something like "//" or "...".
1.) Does "/folders" somehow stand in for (in my case on a mac) "Macintosh HD/Users/<username>/<one more folder which in this case is "SASUniversityEdition">. In other words "/folders" being one folder away from the username? But that makes no sense because data rarely resides under a user name!
2.) And what if there were a folder with just that name "folders"?
3.) How does it work in the real world? I am in a training situation now.
Please help me understand the thinking that SAS uses for this syntax. I cannot make sense of it!
SAS UE runs on a virtual machine that is Unix. So you essentially have a different computer operating on your computer or think of it as a server running on your computer. That computer cannot see your full hard drive or access everything instead it is connected via shared folders that you set up during installation. I believe this is a security restriction on many systems these days to prevent applications from accessing files they shouldn't be but not 100% sure on that component.
SAS UE has been set up so that shared folders are mapped to /folders/myfolders/ so that all users can start with similar paths making it easier to specify the initial path.
You can use a direct path to the files but that's cumbersome by far. Instead SAS allows you to short cut that with the library name and then the data set name. This is similar to setting a schema and table name in a RDBMS.
This would be similar to working on a SAS server so you'll be familiar with the concepts of relative paths.
Also this isn't really a SAS issue - it's an issue related to working with servers and virtual machines. Or think of it as a shortcut to avoid typing out the full path.
@dllb wrote:
In SAS Programming 1: Essentials, lesson 2 I am prompted to write a proc to display contents.
I was unable to do this even after I was give the answer:
proc contents data="FILEPATH/storm_summary.sas7bdat"; run;I didn't understand the FILEPATH.
After some searching in help I found that the correct syntax was:
Proc contents data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat";
run;I understand the portion "/myfolders/WPG194/data/storm_summary.sas7bdat" but I don't understand "/folders"
because at that point it is really "/SASUniversityEdition". How can a literal "/folders" mean something other than what it says? I would expect something like "//" or "...".
1.) Does "/folders" somehow stand in for (in my case on a mac) "Macintosh HD/Users/<username>/<one more folder which in this case is "SASUniversityEdition">. In other words "/folders" being one folder away from the username? But that makes no sense because data rarely resides under a user name!
2.) And what if there were a folder with just that name "folders"?
3.) How does it work in the real world? I am in a training situation now.
Please help me understand the thinking that SAS uses for this syntax. I cannot make sense of it!
Files whose name ends with .sas7bdat are SAS data sets. They are referred to by their data set name, in your case STORM_SUMMARY, or by the library name followed by a dot followed by the data set name, in your case (for exmaple) MYDIR.STORM_SUMMARY.
PROC CONTENTS (and all SAS PROCs) work with data sets named as one of the two possibilities above.
In order to use the two-word name MYDIR.STORM_SUMMARY, you need to tell SAS what exact folder your SAS data sets are stored in. To do this, you use a LIBNAME statement which points SAS to the proper folder. For example:
libname mydir "c:\users\abcdef\documents";
So, the question for you is: what is the exact folder name and path where this STORM_SUMMARY.SAS7BDAT file is located in? Once you know this, you can create the proper LIBNAME statement, and then
proc contents data=mydir.storm_summary;
It is never correct to put the file path and file name in a DATA= part of a SAS proc. So
data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat"
is never correct, the folder name and file name do not go after DATA=
Thank you PaigeMiller,
I am learning how to assign "libname" now however the syntax I showed for PROC CONTENTS had no "libname" assigned and it still used "/folders".
I am looking for an explanation for why the prefix "/folders", in the code that I showed.
Please also see my original questions.
@PaigeMiller wrote:It is never correct to put the file path and file name in a DATA= part of a SAS proc. So
data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat"is never correct, the folder name and file name do not go after DATA=
It's unconventional but it is valid syntax and will work. Just not a good idea and no one uses that in real life. In 15+ years I've never referenced a data set in this manner.
@Reeza wrote:
@PaigeMiller wrote:It is never correct to put the file path and file name in a DATA= part of a SAS proc. So
data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat"is never correct, the folder name and file name do not go after DATA=
It's unconventional but it is valid syntax and will work. Just not a good idea and no one uses that in real life. In 15+ years I've never referenced a data set in this manner.
You may be right, but the documentation for PROC CONTENTS does not say this at all.
SAS UE runs on a virtual machine that is Unix. So you essentially have a different computer operating on your computer or think of it as a server running on your computer. That computer cannot see your full hard drive or access everything instead it is connected via shared folders that you set up during installation. I believe this is a security restriction on many systems these days to prevent applications from accessing files they shouldn't be but not 100% sure on that component.
SAS UE has been set up so that shared folders are mapped to /folders/myfolders/ so that all users can start with similar paths making it easier to specify the initial path.
You can use a direct path to the files but that's cumbersome by far. Instead SAS allows you to short cut that with the library name and then the data set name. This is similar to setting a schema and table name in a RDBMS.
This would be similar to working on a SAS server so you'll be familiar with the concepts of relative paths.
Also this isn't really a SAS issue - it's an issue related to working with servers and virtual machines. Or think of it as a shortcut to avoid typing out the full path.
@dllb wrote:
In SAS Programming 1: Essentials, lesson 2 I am prompted to write a proc to display contents.
I was unable to do this even after I was give the answer:
proc contents data="FILEPATH/storm_summary.sas7bdat"; run;I didn't understand the FILEPATH.
After some searching in help I found that the correct syntax was:
Proc contents data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat";
run;I understand the portion "/myfolders/WPG194/data/storm_summary.sas7bdat" but I don't understand "/folders"
because at that point it is really "/SASUniversityEdition". How can a literal "/folders" mean something other than what it says? I would expect something like "//" or "...".
1.) Does "/folders" somehow stand in for (in my case on a mac) "Macintosh HD/Users/<username>/<one more folder which in this case is "SASUniversityEdition">. In other words "/folders" being one folder away from the username? But that makes no sense because data rarely resides under a user name!
2.) And what if there were a folder with just that name "folders"?
3.) How does it work in the real world? I am in a training situation now.
Please help me understand the thinking that SAS uses for this syntax. I cannot make sense of it!
I believe you missed the & in the original code.
proc contents data="&FILEPATH/storm_summary.sas7bdat";
run;
In the set up you create a macro variable called FILEPATH and you can reference that macro variable later but you need to have the & in front of the fiiepath for that to work.
Hi:
To explain, fully, the use of the string FILEPATH in our Programming 1 class, we intend for the string FILEPATH to be a placeholder for the FULL path to either a library or a file. So references like these which contain the string FILEPATH:
proc contents data="FILEPATH/storm_summary.sas7bdat";
run;
or
%let path=FILEPATH;
libname PG1 "&path";
or
INFILE "FILEPATH/class_birthdate.csv" dlm=',';
should be handled by substituting the correct physical FILEPATH string for the student's method of using SAS, as shown below.
SAS University Edition (if following our recommendations):
proc contents data="/folders/myfolders/EPG194/data/storm_summary.sas7bdat";
run;
or
%let path=/folders/myfolders/EPG194/data;
libname PG1 "&path";
or
INFILE "/folders/myfolders/EPG194/data/class_birthdate.csv" dlm=',';
SAS OnDemand for Academics:
proc contents data="/home/<yourUserID>/EPG194/data/storm_summary.sas7bdat";
run;
or
%let path=/home/<yourUserID>/EPG194/data;
libname PG1 "&path";
or
INFILE "/home/<yourUserID>/EPG194/data/class_birthdate.csv" dlm=',';
SAS local C: drive install with C:\SAS_class main folder:
proc contents data="C:\SAS_class\EPG194\data\storm_summary.sas7bdat";
run;
or
%let path=C:\SAS_class\EPG194\data;
libname PG1 "&path";
or
INFILE "C:\SAS_class\EPG194\data\class_birthdate.csv" dlm=',';
SAS Enterprise Guide assuming used the AUTOEXEC process flow instructions (AUTOEXEC makes &PATH):
proc contents data="&path/storm_summary.sas7bdat";
run;
or
(EG does not need %LET because it is taken care of in AUTOEXEC process flow)
libname PG1 "&path";
or
INFILE "&path/class_birthdate.csv" dlm=',';
The bottom line, ANYTIME in the course where you see the string FILEPATH the intention is for you to use the appropriate file path for the file or library based on YOUR method of accessing SAS.
Hope this helps,
Cynthia
Cynthia_sas,
Thank you.
I have not yet gotten far enough to understand the syntax:
%let path=
And the lesson was not clear enough to explain the "/folder" however that has now been explained to me.
I will refer back to your reply if I need more explanation to the syntax you describe.
No Reeza, There was no "&" present.
The issue has been resolved. FILEPATH was a placeholder where I was to place my actual file path. When I did this correctly then it worked.
@dllb wrote:
No Reeza, There was no "&" present.
The issue has been resolved. FILEPATH was a placeholder where I was to place my actual file path. When I did this correctly then it worked.
You're correct. Cynthia explained the logic behind the 'FILEPATH' name in the cod above.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.