Examples use generated data (datalines) or SASHELP.
1 Code Block
LIBNAME, DATA STEP, PROC PRINT Data
Explanation : The LIBNAME statement assigns the sales libref to a library location. Substitute your library's location for library-path. The location must already exist and be accessible by the SAS Compute Server. The DATA step creates the sales.quarter1 dataset and stores it in the physical library location. The PROC PRINT step refers to the dataset by its two-level name, sales.quarter1.
Macro, %SYSFUNC, fonction LIBNAME, fonction LIBREF
Explanation : The macro variable mylibref specifies the libref name, new. The macro variable mydirectory specifies the library location. Substitute your library's location for library-location. The location must already exist and be accessible by the Compute Server. An IF-THEN-ELSE statement calls the %SYSFUNC macro function, which in turn calls the LIBNAME function to attempt library assignment. If an error or warning occurs, the message is written to the SAS log. If no error or warning occurs, then success is written to the log. Note that in a macro statement, you do not enclose character strings in quotation marks. Another IF-THEN-ELSE statement calls the %SYSFUNC macro function, which calls the LIBREF function to validate the library assignment. Again, if an error or warning occurs, the message is written to the SAS log. If no error or warning occurs, an informational message is written to the log. The test macro executes.
%ELSE %put library &mylibref is assigned to &mydirectory;
10
%mend test;
11
12
%test
3 Code Block
LIBNAME
Explanation : The LIBNAME statement concatenates two SAS libraries. The following figure illustrates concatenation. Note that the index for apples does not appear in the concatenation. The lib2.apples dataset has an index. However, the lib1.apples dataset does not have an index, and lib1 is listed first in the concatenation. SAS removes the index when its associated dataset is not part of the concatenation. If multiple catalogs have the same name, their entries are concatenated. The lib3.formats catalog combines the entries from the lib1.formats and lib2.formats catalogs. For more details, see Catalog Concatenation in SAS V9 LIBNAME Engine: Reference. The key idea is that library concatenation allows you to reference multiple libraries stored in different physical locations. When a dataset is opened for input or update, the concatenated libraries are searched, and the first occurrence of the dataset is used. When a dataset is created, it is created in the first library listed in the concatenation, even if a file with the same name exists in another library in the concatenation. Undesirable behavior could occur if datasets with the same name exist in different locations.
Copied!
libname lib3 (lib1 lib2);
1
LIBNAME lib3 (lib1 lib2);
4 Code Block
OPTIONS, SIGNON, LIBNAME, PROC DATASETS
Explanation : The COMAMID= system option specifies TCP/IP as the communications access method. The myserver macro variable is assigned to the host name of the remote SAS/CONNECT server. The SIGNON statement refers to the myserver macro variable followed by the port number on which the SAS/CONNECT spawner listens. If your port number or service name is defined in the macro variable, omit it from the SIGNON statement. In the LIBNAME statement, do not specify an engine. Specify the location of your data, and specify the myserver macro variable in the SERVER= option. Include the port number if specified in the SIGNON statement. PROC DATASETS runs on the client. Although the client accesses data that resides on the server, the data is not written to the client's local disk.
Explanation : The LIBNAME statement assigns the davdata libref to the URL location of a WebDAV server. The WEBDAV option is required to access a WebDAV server.
Explanation : The LIBNAME statement specifies the mytddata libref and TERADATA, which is the engine nickname for SAS/ACCESS Interface to Teradata. The statement also specifies connection options for Teradata. Modify these options to specify your SAS/ACCESS connection values and any other options you need. The DATA step creates a table named grades. The table resides in the Teradata DBMS and is not a SAS dataset. The PROC DATASETS output for the mytddata library shows that the engine is Teradata. For the grades table, the SAS member type is DATA and the DBMS member type is TABLE.
Explanation : In the LIBNAME statement, the target libref is assigned to a SAS library location. Substitute your library's location for library-path. No engine is specified, so SAS assigns the default V9 engine. This is the same SAS/ACCESS LIBNAME statement as in the 'Access DBMS Data as a SAS Library' example. The DATA step creates a SAS view named highgrades that refers to the Teradata table named grades. The view includes rows where the final variable is greater than 80. PROC PRINT executes the view. Be aware that DATA step views do not retain the LIBNAME statement. Therefore, when you refer to this view, you must first submit the LIBNAME statements for the mytddata library as well as the target library.
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;
Explanation : This example sets the DLCREATEDIR system option to create a subfolder for a library. In the example, the /home/userid/mydata/ folder exists, but the project subfolder does not. Since the DLCREATEDIR system option is set, SAS creates project.
Explanation : This statement deassigns the mylib libref from its physical location.
Copied!
libname mylib clear;
1
LIBNAME mylib clear;
10 Code Block
LIBNAME
Explanation : Use the _ALL_ keyword in the LIBNAME statement to deassign all library assignments (other than system libraries).
Copied!
libname _all_ clear;
1
LIBNAME _all_ clear;
11 Code Block
Macro, %SYSFUNC, fonction LIBNAME
Explanation : You can also use the LIBNAME function. The following code deassigns the new libref, which was assigned in the 'Assign a Libref with a function' example.
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.