Hi, In the official SAS specialist prep guide, page 46 on reading a SAS data set to create another data set, here is the screenshot.
I do understand the purpose of line 2 is to create a library where I can store the MALES dataset. However, there is no file or folder called "Men50" in the 'C:\Users\Student1\cert\' directory. The book does NOT tell us to create a folder called "Men50" before you use LIBNAME statement to reference it.
So when I ran the code, I got an error even though I can see that MEN50 library was successfully created by SAS. So my question is, we always need to create the folder or make sure it exist in the physical file path before using LIBNAME to create a library for it?
The folder you have circled on the left is a LIBREF and not an operating system directory.
To see the files and directories that exist on the computer where SAS is running use the Files and Folders panel instead of the Libraries panel. (Don't ask me why they call directories folders.)
Remember that on Unix filenames (directories are just special files that hold information about the files that exist in them) are case-sensitive. So a file named MEN50 would be a different file than one named Men50 or men50 or meN50.
The folder you have circled on the left is a LIBREF and not an operating system directory.
To see the files and directories that exist on the computer where SAS is running use the Files and Folders panel instead of the Libraries panel. (Don't ask me why they call directories folders.)
Remember that on Unix filenames (directories are just special files that hold information about the files that exist in them) are case-sensitive. So a file named MEN50 would be a different file than one named Men50 or men50 or meN50.
I thought SAS convert all file names and variable names to upper case anyway.
@Nietzsche wrote:
I thought SAS convert all file names and variable names to upper case anyway.
SAS data set names and variable names, but not file names and paths, which are system dependent. SAS code is case insensitive.
And it depends on the underlying OS settings. Windows is case insensitive, but Linux is usually a case sensitive system.
FYI - this is typically true in many programming tools not just a SAS feature.
So my question is, we always need to create the folder or make sure it exist in the physical file path before using LIBNAME to create a library for it?
It depends on your option setting.
There's an option in SAS called DLCREATEDIR & NODLCREATEDIR.
specifies to create a directory for a SAS library that is named in a LIBNAME statement if the directory does not exist.
Restriction | If the path specified in the LIBNAME statement contains multiple components, SAS creates only the final component in the path. If any intermediate components of the path do not exist, SAS does not assign the specified path. For example, when the code libname mytestdir ‘c:\mysasprograms\test’ executes, and c:\mysasprograms exists, SAS creates the test directory. If c:\mysasprograms does not exist, SAS does not create the test directory. |
---|
specifies not to create a directory for a SAS library that is named in a LIBNAME statement.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.