In my SAS on Demand code, the LIBNAME was copied from its entry on the left panel, but it produced an error shown in the attachment below. Could someone please tell me how to fix it?
Libnames typically point to storage locations, i.e. folders. The exceptions are things like XLSX files where each "tab" would be treated as a data set in a library.
Your file the libname points with the SAS extension is likely a TEXT file and not valid for a library. Remove the file name and just use the folders and see if that helps.
I have attached a snip showing the left panel in my SAS on Demand session (SASOnDemandLibname04.pdf). I altered my SAS code for the LIBNAME and INFILE statements to point to the Windows 10 folder and its file containing my data (SASOnDemandLibname05.pdf). Still no success. Someone please tell me what's wrong.
Thanks
So the error messages are very clear.
There is not a file named 'weight01.dat' in the current working directory of '/pbr/biconfig/940/Lev1/SASapp/'. There is also no subdirectory of that location named 'C:\DATA\SAS\Weight'. To use an absolute path on a UNIX operating system the path must start with the root node. That is the leading / you can see in the error message.
If you want to see what is the path to reference the Weight directory just right click on
and select properties. One of the properties will be the path.
Or you could just try using ~ (tilda character) to indicate that you want the path to start from your userid's home directory.
libname wght '~/Weight';
...
infile '~/Weight/weight01.dat' ...
I have attached a snip from my log showing the LIBNAME and INFILE statements with the tilda, but the error persists. What have I done wrong?
In right-clicking the file directory in the left panel, I found the following locations:
/home/u57995729
/home/u57995729/sasuser.v94
/home/u57995729/Weight/weight01.dat
I have searched for documentation on the LIBNAME statement on the Internet for SAS but the only response was an offer for training.
I also searched for 'tilda' in the shortcuts documentation but it could not be found.
Your help is much appreciated.
Use the LIBNAME keyword only once in the LIBNAME statement.
There is a syntax error in your screenshot that you embedded into a PDF and then attached as a file. (Why go to all that work? If you have to attach a photograph just click on the icon that looks like a camera. But better still click on the </> icon and insert the actual text from the SAS log)
You have the the keyword LIBNAME twice. The second one is the place where you could tell SAS to use a special engine for defining the libname (like XLSX or ODBC or ORACLE or XPORT).
So given the paths you are showing these statements should work.
libname home '/home/u57995729';
libname sasuser2 '/home/u57995729/sasuser.v94';
libname weight '/home/u57995729/Weight';
filename in '/home/u57995729/Weight/weight01.dat';
data weight.weight01;
infile in ;
input ....
So the first three are LIBNAME statements to create three librefs that point to the three folder (directory) names that you included. The next is a FILENAME statement to create a fileref that points to the one filename that you included.
I changed the LIBNAME statement to use WEIGHT as the libref. You can use up to 8 characters in a libref (or a fileref).
I change the DATA statement to create a permanent dataset by writing it into the directory where the .dat file lives.
You will need to complete the rest of the DATA step as I am not sure what you .dat file contains.
Here is a way for you to have SAS show some of the content of the .dat file into the SAS log so you can review it and decide how to write the data step to read it. It will read just the first 5 lines and write them to the SAS log with a ruler so you can see in which column the characters appear.
filename in '/home/u57995729/Weight/weight01.dat';
data _null_;
infile in obs=5;
input;
list;
run;
The SAS session on which you run your code does not have access to your desktop's storage, as it runs in the cloud.
The only access that On Demand provides is the upload/download facility of SAS Studio.
This is the reason why your LIBNAME does not work. You can define a library reference only for directories on the server where you have the necessary permissions, which usually means subdirectories of your home directory.
It makes no sense to point a LIBNAME at a SAS program file.
You could point a FILENAME to it.
But you probably want to instead just open it in the editor and run the code it contains.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.