Thursday, April 27, 2017

Library Assignment Basics (SAS)


A common error that is often encountered by novice SAS programmers, is the utilization of the SAS Enhanced Editor UI to assign libraries. As you are probably well aware, unless programmed otherwise, SAS only maintains the “Work” Library between sessions. Since the “Work” Library is only a temporary cache, recognizing and maintaining libraries at the beginning of each SAS session is an absolute necessary. 

The cumbersome way to assign a library through the SAS UI is to follow the steps below (FOR DEMONSTRATION PURPOSES ONLY. DO NOT ASSIGN LIBRARIES IN THIS WAY):

In the SAS Enhanced Editor, click the “Tools” menu drop down. This is the fourth option from the left.


From this menu, click “New Library”.

Once this has performed, you should be presented with the menu:


Simply name your library*, and choose the established pathway. After clicking “OK”, assuming that there were no errors, SAS should have assigned the library. No messages indicating this will be printed to the SAS log. Therefore, you must manually check the graphical interface by clicking on “Libraries” within the “Explorer” window.



Assigning Libraries the Right Way

A much easier method for library assignment is to utilize program code within the program that you are creating. I believe that the best play to create this assignment is within the program header.

The code line to assign libraries is:

Libname <NAMEOFYOURLIBRARY> “<path of your library>";

In the case of our previous example, this would resemble the following:

Libname Test “H:\TestLib”;

Running this line independently will produce the following log window message:


*Library naming limitations

A SAS Library name is 1 to 8 characters long, begins with a letter or underscore, and contains only letters, numbers, or underscores. Not complying with these rules is typically what causes errors when assigning SAS libraries.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.