BookmarkSubscribeRSS Feed
KKinslow79
Calcite | Level 5
Im a new SAS user and need help creating a library. Im a grad student and I need all the help you all can offer!
2 REPLIES 2
Cynthia_sas
SAS Super FREQ

Hi:

  Let's say I have 3 SAS datasets:
students.sas7bdat
teachers.sas7bdat
courses.sas7bdat

 

And that these 3 datasets are physically stored in these possible locations/operating systems:
1) SAS On Windows on my local machine:
C:\Schools\K_12\Douglas
Then the LIBNAME statement would be:
libname Douglas 'c:\Schools\K_12\Douglas';

 

2) SAS On Windows, but mapped to my Q:drive
Q:\user111\Schools\K_12\Douglas
Then the LIBNAME statement would be:
libname Douglas 'q:\user111\Schools\K_12\Douglas';

 

3) SAS on a Unix/Linux server on a local network:
/home/usr/bin/usr111/Schools/K_12/Douglas
Then the LIBNAME statement would be:
libname Douglas '/home/usr/bin/usr111/Schools/K_12/Douglas';

 

4) SAS used with SAS OnDemand for Academics under a users Files (Home) top folder:
/home/u12345678/Schools/K_12/Douglas
Then the LIBNAME statement would be:
libname Douglas '/home/u12345678/Schools/K_12/Douglas';

 

Notice how each libname statement uses a "nickname" or library reference called Douglas in order to provide a reference that will point to that physical location on each operating system.

 

Now, no matter which operating system my files are physically stored on, this code below would work the same if run on each operating system, assuming the correct LIBNAME statement had been issued prior to running the steps.

  In this case, since the files are permanently stored in a physical location on my operating system and since I now want to use SAS procedures with the SAS data, I can use a 2-level name in my SAS code to point to the specific SAS data table and SAS will know where to get the data from the folder location specified in the LIBNAME statement.

 

proc contents data=douglas.students;
title 'Show information about students at Douglas';
run;

proc print data=douglas.teachers;
title 'Display a list of teachers at Douglas Elementary';
run;

proc freq data=douglas.courses;
title 'Show how many courses in each grade_level at Douglas';
tables grade_level/ nocum nopercent;
run;

 

Hope this helps get you started. Our Programming 1 class goes into some detail about the LIBNAME statement to read SAS data and the XLSX Libname engine to read Excel files and helps you learn how to read CSV files and import them into SAS format. It's a free class and might be worth reviewing.

Cynthia

ballardw
Super User

You will want to make sure that the path for the library location starts at Drive (windows) or disc mount point or root of your access. If the path does not specify such then you would get a path relative to a possibly changing disc location, such as where SAS is executing, and not where you intend.

 

Also you need to have permission to read that location and if you want to create data sets write permissions.

 

If your SAS session is running from a server the path needs to be as the SAS server sees things. Which means that it may not see your local hard drive.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 463 views
  • 0 likes
  • 3 in conversation