Examples use generated data (datalines) or SASHELP, with the exception of examples accessing external sources (SAS/CONNECT, WebDAV, DBMS) for which simulated data or placeholders are used.
1 Code Block
DATA STEP / PROC PRINT Data
Explanation : This example assigns the libref 'sales' to a specified library path. It then creates a 'quarter1' dataset in this library using a DATA step, and then uses PROC PRINT to display the contents of the dataset. The library path must exist and be accessible by the SAS Compute Server.
Explanation : This 'test' macro program dynamically assigns a libref ('new') to a directory location ('library-location') using the LIBNAME function. It then checks for successful assignment with the LIBREF function and displays an appropriate message. Paths must be valid and accessible. Functions are preferred for programmatic assignments.
%ELSE %put library &mylibref is assigned to &mydirectory;
10
%mend test;
11
12
%test
3 Code Block
LIBNAME Statement
Explanation : This LIBNAME statement concatenates two existing SAS libraries, 'lib1' and 'lib2', under the new libref 'lib3'. This allows access to data from both libraries using a single libref. When searching for a dataset, libraries are explored in the order of their list. If a dataset is created, it is placed in the first library of the concatenation.
Copied!
libname lib3 (lib1 lib2);
1
LIBNAME lib3 (lib1 lib2);
4 Code Block
LIBNAME Statement / PROC DATASETS
Explanation : This example illustrates how to access a SAS library located on a remote server via SAS/CONNECT. It establishes a TCP/IP connection, connects to the remote server ('myserver') with credentials, and then assigns the libref 'reports' to a remote directory. PROC DATASETS is then used to inspect the remote library. The SAS/CONNECT session is then closed.
Explanation : This LIBNAME statement assigns the libref 'davdata' to a directory on a WebDAV server. The 'WEBDAV' option is crucial for specifying the access method. Credentials (user and password) are provided for authentication. SAS will temporarily retrieve files to the local disk for processing, then return them to the server after modifications.
Explanation : This example assigns the libref 'mytddata' to a Teradata database, allowing access to tables as SAS datasets. A DATA step is used to create a 'grades' table directly in the Teradata database. PROC DATASETS is then used to display information about this table. It should be noted that SAS/ACCESS interfaces do not always support the REPLACE= option for DBMS tables.
Explanation : This example creates a SAS view named 'highgrades' from an existing Teradata table ('mytddata.grades'). The view selects only records where the 'final' variable is greater than 80. PROC PRINT executes this view, and PROC DATASETS shows that 'highgrades' is indeed a SAS view. The librefs for 'target' and 'mytddata' must be assigned before this view can be used.
Copied!
libname target 'library-path';
libname mytddata teradata server=mytera user=myid password=mypw;
data target.highgrades / view=target.highgrades;
set mytddata.grades;
where final gt 80;
run;
proc print data=target.highgrades;
run;
proc datasets library=target;
run;
quit;
Explanation : This example shows how to automatically create a subfolder for a SAS library if it does not exist. The 'DLCREATEDIR' system option is enabled, allowing SAS to create the 'project' folder if it is missing from the specified path '/home/userid/mydata/project' when assigning the 'mynewlib' libref.
Explanation : This LIBNAME statement de-assigns the libref 'mylib' from its physical location. This is useful for freeing up resources or changing a libref's assignment. To de-assign all librefs (except system libraries), 'libname _all_ clear;' can be used.
Copied!
libname mylib clear;
1
LIBNAME mylib clear;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.