BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Obsidian | Level 7

Screen Shot 2022-09-21 at 1.46.06 PM.png


Having difficulty moving data for class_birthdate.sas7bdat in the data folder to a newly created folder. I am taking the SAS programming 1 and trying to practice this function.


Sometimes I have difficulty creating a libname too. For example, I tried writing libname MYWORK "EPG1V2/data/class_birthdate.sas7bdat";


What am I doing wrong?


Accepted Solutions

One way to see the names of the sheets in the XLSX file is to use the XLSX LIBNAME engine. For example, we have a multi-sheet workbook called STORM.XLSX in the EPG1V2 data folder. So with this LIBNAME XLSX (below) statement, you could run the PROC CONTENTS to see the names of all the SHEETS. And one of the sheets is named storm_2017, so this code would work to do the PROC CONTENTS and then print some rows from the storm_2017 sheet:
libname xl_storm xlsx 's:\workshop\EPG1V2\data\storm.xlsx';  /* windows */


libname xl_storm xlsx '/home/<userID>/EPG1V2/data/storm.xlsx'; /* SAS OnDemand */

proc contents data=xl_storm._all_;

proc print data=xl_storm.storm_2017 (obs=20);
libname xl_storm clear;

The other way to see the names is to open the file with Excel. However, the XLSX file won't be opened on the SAS OnDemand server because it is a Linux server and it doesn't have Excel. so the PROC CONTENTS method is the programmatic way to see the sheets in the workbook.

View solution in original post

Diamond | Level 26

In SAS, you refer to SAS data set names without the .SAS7BDAT on the end.



Paige Miller
Obsidian | Level 7
Thank you, but now I receive an error message saying that "ERROR: File MYWORK.CLASS_BIRTHDAT.DATA does not exist."

Diamond | Level 26

Whenever you get an ERROR, you should show us the log (all of the log for the PROC or DATA step that has an error, not selected parts of it, all of the log for that PROC or DATA step). Please also copy the log as text (not screen capture) and paste it into the window that appears when you click on the </> icon.


Paige Miller
Obsidian | Level 7

Sorry I clicked quick reply instead a full reply so I could not send a screen shoot before.


I'm taking the live programming class and these are some screen shots from that class and my SAS studio log


Screen Shot 2022-09-21 at 2.20.31 PM.png

Screen Shot 2022-09-21 at 2.20.45 PM.png

Screen Shot 2022-09-21 at 2.21.46 PM.png

Screen Shot 2022-09-21 at 2.22.49 PM.png

Screen Shot 2022-09-21 at 2.42.03 PM.png


Screen Shot 2022-09-21 at 2.42.13 PM.png

Screen Shot 2022-09-21 at 1.46.06 PM.png


Screen Shot 2022-09-21 at 1.45.33 PM.png

I was successful momentarily in my last attempt to create a library, but I wanted to try again using other instructions given.

Super User
In your screenshots you shouldn't have quotes before the dataset name. I can see the course does, but when referring to a data set with the libname method that notation is incorrect. Quotes are used for when specifying the full path name. The libname method simplifies this so you don't have to always type out the full path name.

Obsidian | Level 7

Screen Shot 2022-09-21 at 3.07.16 PM.png


No luck

This is valid PROC CONTENTS syntax:
proc contents data="/home/<userID>/EPG1V2/data/storm_summary.sas7bdat";
That is what the first slide is showing. In that example, we are showing the students that it is POSSIBLE to use a fully qualified file name and file extension in the DATA= option of PROC CONTENTS.

Then, we show them the LIBNAME syntax. The LIBNAME syntax on SAS OnDemand for Academics for the Programming 1 class would be:
libname PG1 "/home/<userID>/EPG1V2/data";

Note that there is NOT a physical filename and file extension on the LIBNAME statement because the LIBNAME statement is pointing to a collection of SAS files, whereas the PROC CONTENTS example with a physical file name was pointing to just one file. So the equivalent PROC CONTENTS for the storm_summary SAS dataset using the 2 level reference would be:
proc contents data=PG1.storm_summary;

Note that when you use the 2 level name -- libname.datasetname -- there are NOT any quotes. However, when you use the physical path location for PROC CONTENTS, there do need to be quotes. I think that somehow the confusion came in understanding the difference between a physical file name shown once in the class and having just one practice in the class. After we show the use of the LIBNAME statement in class, we NEVER show the physical file method again, ever. So that one example was mean to be something of a motivation for why the LIBNAME statement is very useful -- because is makes it possible for you to run the SAME program on 2 different operating systems, by just changing the LIBNAME statment.

For example, I can write and test THIS code on my instructor machine:
libname PG1 's:\workshop\EPG1V2\data';
proc contents data=PG1.storm_summary;

proc print data=PG1.storm_summary;

and then I can give that code to my co-worker on a UNIX system and then ONLY need to change the LIBNAME statement to the location for the data on their system
LIBNAME PG1 '/usr/sasdqd/myclass/EPG1V2/data';

...and ALL the rest of the code could run unchanged.

Note that there is NOT any file name or file extension in the LIBNAME statement.
Super User Tom
Super User

In your first screenshot you have two of the most frequent SAS coding mistakes.

Missing semicolon and unbalanced quotes.  


On line 71 you never ended the LIBNAME statement so SAS thinks that the words  PROC, CONTENTS and DATA= are some type of LIBNAME options that comes after the path.  (There are such things, for example you can add ACCESS=READONLY to help prevent you from modifying any of the datasets in that library).


Then in line 73 you started to put quotes around the dataset name (which is also a mistake), but you never closed the quotes.   So that means that everything up to the next quote will be considered part of the quoted string being used as the value of the DATA= option.


In your next photograph you show an invalid dataset name.  


The part before the period is name assigned in the LIBNAME statement, the libref.  The part after period is the dataset name (the member name).  Dataset names cannot contain periods (unless you set the system option VALIDMEMNAME to EXTEND, but then you would need to use a NAME LITERAL and not just the bare period you used.)


The name of the DATASET is CLASS_BIRTHDAT (dataset names are NOT case sensitive).


The name of the FILE that SAS uses to store the dataset is class_birthdat.sas7bdat (filenames on a Unix operating system ARE case sensitive and SAS datasets names never use uppercase letters on Unix).



Super User

Can you show a screenshot of the mywork library expanded in the corner to show the data set name?


If not, what happens when you run the following:

proc contents data=mywork._all_;







Super User Tom
Super User

Two things.

1) A libname points to a DIRECTORY (what the SAS/Studio user interface calls a "folder").  You are attempting to point to an individual FILE.


2) You need specify the full name of the directory (also called a full path).  Otherwise the operating system will consider the name as being RELATIVE to its current working directory.  If you are running SAS via SAS/Studio or Enterprise Guide or some other front end tool then you will not normally have any control over what the default current directory will be.  And you most likely will not have write access to create any files under that directory.  


On Unix (which where SAS is running for most SAS/Studio users) a full directory name starts with the root node which is indicated by a leading slash ( / ).  You can also usually start the name (path) with the ~ character and that will point to your personal home directory.


So try a path more like:

libname MYWORK "~/EPG1V2/data/";

Now if you want read or write a dataset named CLASS_BIRTHDATE from that directory you can use the two level name of:


In your SAS code.


So if you already have that class_birthdate.sas7bdat file in the data subdirectory of the EPG1V2 subdirectory of your home directory then you could check its contents by running this code:

proc contents data=mywork.class_birthdate;
Obsidian | Level 7

Screen Shot 2022-09-21 at 3.03.23 PM.png


I think I get it now, but it still does not work. I don't know what I am doing wrong.

SAS Employee



You forgot to put the forward slash after the ~ in your libname statement.

Obsidian | Level 7

Screen Shot 2022-09-22 at 12.54.52 PM.png


Finally, it worked!. Thank you. I think this is also challenging for me, because there are so many detailed functions to remember like quotes, semicolons, and capitalizations, not to mention I am dyslexic. 


Screen Shot 2022-09-22 at 12.57.08 PM.png

 Now is this directory stored in this new folder I created permanently? 


Obsidian | Level 7

Ok, I have another libname issue. When performing the Programming 1 Essentials: Lesson 2. I'm using p102d02 and this is the code I am running to make a folder for XLSTORM.


options validvarname=v7;

libname xlstorm xlsx "s:/workshop/data/storm.xlsx";

proc contents data=xlstorm.storm_summary ;

libname xlsx clear;

I only highlighted the first two lines as instructed and was able to successfully create the folder, but there is no storm_summary content.



Screen Shot 2022-09-22 at 1.47.55 PM.png

When I try to run everything this is the message I receive.


 71         options validvarname=v7;
 73         *Complete the LIBNAME statement;
 74         libname xlstorm xlsx "s:/workshop/data/storm.xlsx";
 NOTE: Libref XLSTORM was successfully assigned as follows: 
       Engine:        XLSX 
       Physical Name: s:/workshop/data/storm.xlsx
 76         *Complete the DATA= option to reference the STORM_SUMMARY worksheet;
 77         proc contents data=xlstorm.storm_summary ;
 ERROR: File XLSTORM.storm_summary.DATA does not exist.
 78         run;
 NOTE: Statements not processed because of errors noted above.
 NOTE: PROCEDURE CONTENTS used (Total process time):
       real time           0.00 seconds
       user cpu time       0.00 seconds
       system cpu time     0.00 seconds
       memory              1942.53k
       OS Memory           30008.00k
       Timestamp           09/22/2022 08:48:22 PM
       Step Count                        127  Switch Count  0
       Page Faults                       0
       Page Reclaims                     545
       Page Swaps                        0
       Voluntary Context Switches        0
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           8
 NOTE: The SAS System stopped processing this step because of errors.
 80         libname xlsx clear;
 WARNING: Libref XLSX is not assigned.
 User: u60771588

Your help is appreciated.



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!

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
  • 21 replies
  • 10 in conversation