BookmarkSubscribeRSS Feed
Calcite | Level 5

In my SAS class we learned how to save files directly to our computer. We were taught to type in libname -name of file- "c:mydata"; 


Another example that was provided was: 

libname hrs “C:\Mydata\PsyData\HRS”;


Does HRS stand for something specific in SAS? 


Our professor and his TA mentioned that we need to know how we need to know how to make SAS library that is pertinent to the local directory where the file is saved.


I am not sure what any of this means! 


This is how we are required to save things onto our computer. I downloaded the data from the online learning platform that we use. I opened it and have spent the last four hours just trying to save it let alone trying to "tabulate data". My professor doesn't answer emails over the weekend, and I have spent the total of two days trying to do this. I am using SAS 9.4 on my computer that I got from the university. 


Does anyone have any ideas of what I should do? Or how you do this. The only thing the teacher typed in on the first day was that "c mydata" and no matter what I do it doesn't work. I have been reading My Little SAS book and SAS for Dummies and I am not sure what I am missing but my future depends on my understanding of this program. 


If you have to type in a code to make a permanent library, why is their save button on the top of the screen? Does anyone have any recommendations for mastering this program? 


Also, if you can explain this to me like I am six that would be great. Spending hours every single day working on this hasn't been helping my brain. 


Is there a online resource of every single SAS error that has the solution for fixing the problem?


Super User Tom
Super User

The simple LIBNAME statement you posted:

libname hrs “C:\Mydata\PsyData\HRS”;

Consists of three parts.  The LIBNAME keyword that indicates it is a libname statement.  The libref (in this case HRS) which is the name you have chosen to use for referencing the library.  And the location (in this case an existing directory on the C: drive) where the library physically exists.


The HRS is the logical name you will use in your code to access the library.  I can be any valid SAS name that is from one to 8 bytes long.  So consists of letters, digits and underscore but does not start with a digit.


The path or directory name must be a string literal (enclosed in quotes, either the double quote characters in your example or single quote characters) that is an existing directory (some people like to call these FOLDERS) on the machine where SAS is running.


So using C: as the starting of the directory will work if SAS is running on a WINDOWS machine that has a disk drive mapped to the drive letter C.  If your SAS is running on Unix the way you specify a directory name is different.  It would start with the root node / and then have one or mor subdirectory names separated by / instead of the \ used by Windows.


Note that if you are using Enterprise Guide or SAS/Studio to submit your SAS code it is very likely that SAS itself (as opposed to Enterprise Guide or the browser you are using to connect to SAS/STudio) is running on a different machine than they one your keyboard and mouse are connected to.  So you could be using an IBM PC running Windows but still need to use Unix directory names because SAS itself is running on some Unix server.

Calcite | Level 5




I was trying to do what you said. I have the file downloaded from my class. I don't know if I need to change its name. It keeps existing in the downloading folder, so I made a data folder and moved it there. So, I opened the SAS data that I had I think it is called psyda3 oI think I should call it hw3 because it is our third homework assignment. I typed this in: 


libname hw3 "c/hw3";


I then tried the same program with the original name of the data.

libname psyda3"c/psyda3";


I know the data is in the folder because I can see it. It is still not saving there. 


I uploaded a photo of the folder that I am trying to upload it to. I have no idea what is going on. 

Opal | Level 21

According to your screenshot, your LIBNAME should look like this.

libname hw3 "c:\hw3";

An easy way to confirm this is to use Windows Explorer, navigate to your HW3 folder, then copy the path like I've done on my PC:


Then paste that path into your SAS LIBNAME. That way, even if you don't know about naming Windows paths, you can still get it right.


Note: I am assuming that you are running SAS on your PC as you mentioned that in your first post.

Super User Tom
Super User

Note that downloading the file to your PC will only work if SAS is actually running on your PC.


If SAS is not running on your machine then you need to first upload it from your PC to the machine where SAS is running and then use the path of where you put in on that machine in your LIBNAME statement.


c/hw3 is probably not a valid path to a directory.  What that means to SAS is to look for a directory named c in the current working directory that has a sub-directory named hw3.


If you are using a PC and made a directory at the top level of the C: drive named hw3 then you would reference it as c:\hw3.  (Take a introductory course on how PC's organize their files to learn more.)


If you are using a Unix machine then might want to put the file(s) into a subdirectory of your home directory.  On 99% of Unix machines you can reference your home directory using ~.  So if you made a directory named hw3 in your home directory you could reference it with the path ~/hw3.


And if you are using VIYA there are other complications you need to worry about.

Super User

@cognitionotter wrote:

In my SAS class we learned how to save files directly to our computer. We were taught to type in libname -name of file- "c:mydata"; 


Another example that was provided was: 

libname hrs “C:\Mydata\PsyData\HRS”;


Does HRS stand for something specific in SAS? 


HRS is the name of the created library. So you would address data sets in that library as HRS.SomeDataSetName.

Libraries have restrictions on names. The name must start with either a letter or the underscore character, _ , consist only of letters, the underscore or numerals and have a maximum of 8 characters in the name.


The folder in the name should already exist, so you may need to make it using system tools. There are SAS tools to help with that but may cause more problems until you get the basics down.


Many users will pick a library name that has something to do with project. If my data and such related to football it might use Libname Football "d:\somefoldername\football_data_foldername";


There is no single solution to any given problem because you may have many ways of creating the same error message and often there can be multiple solutions depending on the exact error.


Suggestion: ALWAYS read your SAS log. It will quite often tell you what you did wrong and sometime provide suggestions for solutions.

A couple of examples. Two of these violate the name rules from above. The other is attempting to access a folder on the system that the user does not have permissions to use (students get this not infrequently because they don't understand the file structure of the computer(s) they are working on). The "fix" in the first two errors are to bring the name into compliance with the rules. The fix for the third is to make sure that the folder you want to use allows you to use it.

1047  libname libtoolong "C:\somefoldername";
ERROR: libtoolong is not a valid SAS name.
ERROR: Error in the LIBNAME statement.
1048  libname lib+long "C:\somefoldername";
ERROR: Libref in LIBNAME statement must be followed either by quoted
       string or engine name or semicolon; "+" found.
ERROR: Error in the LIBNAME statement.
1051  libname liblong "C:\System Volume Information";
ERROR: User does not have appropriate authorization level for library
ERROR: Error in the LIBNAME statement.

Computer programs are a way to instruct a very stupid machine that does not read your mind how to do something. It requires very exact use of the language for each bit. SAS will actually try to help with some common problems. Here is an example:

1052  prog print data=sashelp.class;
WARNING 14-169: Assuming the symbol PROC was misspelled as prog.
1053  run;

PROC PRINT, proc is short for "procedure", is one of the basic tools to display the contents of a data set or make simple reports. The log above shows that I misspelled "proc" as "prog". The output is actually created as if I submitted Proc Print but the Warning (NOT an error) in the long is a reminder that I should use Proc.


Follow examples EXACTLY. After you get the same results then try modifying the code to try other things.

Depending on your SAS installation you may have a section of On Line Help, possibly accessed with the F1 key, that actually has a section labeled "Learning to Use SAS" under the Contents tab that has a number of stand alone programs. The on line help for specific procedures often have example code with sections of "what it does" explaining sections of the code.


When it comes to SAS coding I "cheated" by learning five different programming languages with different dialects of some of them (FORTRAN and BASIC come in multiple flavors).



Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 5 in conversation