Saturday, 11 August 2012

NOTE: When WORK is not WORK

When you code a one-level data set name, i.e. a data set name with no libname specified, you probably expect it to be read or written from/to the WORK library, but that might not be so. Read on...

Subject to the value of the USER= option, one-level data set names refer to the USER libname if such a libref is allocated; if not, they're written to WORK.

Here's an illustrative log. You can see how the same DATA statement is used in the two separate DATA steps (apparently implying the same output data set). Yet the NOTEs in the log show you how the behaviour changes after the USER libref has been assigned.

17         data demo;
18           x='first';
19         run;

NOTE: The data set WORK.DEMO has 1 observations and 1 variables.

21         libname user '~';
NOTE: Libref USER was successfully assigned as follows: 
      Engine:        V9 
      Physical Name: /home/ratclac
23         data demo;
24           x='second';
25         run;

NOTE: The data set USER.DEMO has 1 observations and 1 variables.

Once the USER libref has been assigned, the only means of accessing the WORK library are:

  • Clear the USER library, e.g. libname user clear;
  • Specify WORK as the first qualifier for a data set name, e.g. data work.demo;

Knowledge of the USER option can form a very useful debugging technique whereby you can quickly switch your code between creating temporary work data sets (normal mode of operation) and permanent user data sets (for debugging).

You can find documentation at the links below:

However, why can I find it in the Unix Companion but not the Windows Companion? In fact, why can't I find it in the OS-independent companion. Answers on a post card please. Am I simply being myopic??