Search notes:

SAS statements: libname

The length of a libname cannot be longer than 8 characters. A notable exception is the reserved libname dictionary.
The return code of the most recent libname statementis stored in &syslibrc.

Windows path

libname tq84_win 'p:\ath\to\windows\directory';

proc datasets
     lib=tq84_win;
run;
Github repository about-SAS, path: /programming/statements/libname/windows-path.sas

(Logically) concatenated libraries

libname tq84_d1 'p:\ath\to\directory\one';
libname tq84_d2 'p:\ath\to\directory\two';
libname tq84_d3 'p:\ath\to\directory\three';

%macro create_tab(lib_no,nam);
  create table tq84_d&lib_no..&nam(
    col_1 numeric,
    col_2 char(10)
  );
  insert into tq84_d&lib_no..&nam values(&lib_no,"&nam");
%mend;

proc sql;
   %create_tab(1,foo);
   %create_tab(2,bar);
   %create_tab(3,baz);
quit;

/*
    Create a concatenated library (tq84_all). With this library, it is possible
    to access tables in different libraries (and locations) with a single libref.
*/

libname tq84_all (
  tq84_d1,
  tq84_d2,
  tq84_d3
);

proc sql;
  /*
      The following view is created in the 
      tq84_d1 library.
  
  */
  create view tq84_all.foo_bar_baz as
    select * from tq84_all.foo union all
    select * from tq84_all.bar union all
    select * from tq84_all.baz;
quit;

proc sql;
  select * from tq84_all.foo_bar_baz;
quit;
Github repository about-SAS, path: /programming/statements/libname/concatenated.sas

clear

Deallocate the library after use:
libname tq84_win 'p:\ath\to\windows\directory';

/*

    do stuff.

*/

libname tq84_win.clear;
Github repository about-SAS, path: /programming/statements/libname/clear.sas

Connecting to a Server

Using the server option to connect to a remote host/server:
%let tq84_srv=host.renenyffenegger.ch 5105;

options comamid=tcp;
options netencrypt
        netencryptalgorithm=SASProprietary;

signon  tq84_srv
        noscript
        user=tq84
        password="{SAS002}5D71C73D177DE3AB1488316D52BDEBDE1ADDF998";

libname tq84_lib "abc.defghi.jklmno.sasdb"
        server = tq84_srv
        disp   = shr;        

proc sql;
  select * from tq84_lib.foo_bar;
quit;

libname tq84_lib clear;
Github repository about-SAS, path: /programming/statements/libname/server.sas

Automatically creating directories

The dlcreatedir option can be used to automatically create a directory with a libname statement if the directory does not exist.

See also

SAS statements, pathname
SAS statements: libname / sql_functions option
libname is a global statements.

Index