BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Sassy_lady
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?

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:
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 */

**OR;

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


proc contents data=xl_storm._all_;
run;

proc print data=xl_storm.storm_2017 (obs=20);
run;
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.
Cynthia

View solution in original post

21 REPLIES 21
PaigeMiller
Diamond | Level 26

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

 

 

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

PaigeMiller
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.

PaigeMiller_0-1663012019648.png

--
Paige Miller
Sassy_lady
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.

Reeza
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.

Sassy_lady
Obsidian | Level 7

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

 

No luck

Cynthia_sas
SAS Super FREQ
Hi:
This is valid PROC CONTENTS syntax:
proc contents data="/home/<userID>/EPG1V2/data/storm_summary.sas7bdat";
run;
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;
run;

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;
run;

proc print data=PG1.storm_summary;
run;

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.
Cynthia
Tom
Super User Tom
Super User

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

Missing semicolon and unbalanced quotes.  

Tom_0-1663801716522.png

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.  

Tom_1-1663802056331.png

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).

 

 

Reeza
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_;
run;

 

 

 

 

 

 

Tom
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:

mywork.class_birthdate

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;
run;
Sassy_lady
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.

brzcol
SAS Employee

Hi,

 

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

Sassy_lady
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? 

 

Sassy_lady
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 ;
run;

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.

 

1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 70         
 71         options validvarname=v7;
 72         
 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
 75         
 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.
 79         
 80         libname xlsx clear;
 WARNING: Libref XLSX is not assigned.
 81         
 82         
 83         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 94         
 User: u60771588

Your help is appreciated.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

LIBNAME 101

Follow along as SAS technical trainer Dominique Weatherspoon expertly answers all your questions about SAS Libraries.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 21 replies
  • 3431 views
  • 9 likes
  • 10 in conversation