Published on :
Data Access CREATION_INTERNE

Examples: Managing SAS Libraries

This code is also available in: Deutsch Español Français
This functional analysis details the key concepts of SAS© procedures for library management. PROC MIGRATE is the preferred method for updating library members to a newer SAS© version, adapting the data representation and encoding to the target library. A SAS©/CONNECT server is required if direct access to the source library is not possible via NFS, or if the source library contains catalogs with incompatible data representation. CEDA (Cross-Environment Data Access) allows read-only access but with performance restrictions. To avoid truncation during encoding changes, the CVP engine can be used with PROC MIGRATE.
PROC COPY is a versatile utility for copying, renaming, or moving datasets and their associated files. The NOCLONE option must be specified when copying to a different operating environment or encoding to adjust data attributes. File system utilities for managing SAS© files are generally not recommended.
PROC CPORT and PROC CIMPORT procedures offer a two-step method (creation then import of a transport file) for moving libraries between environments, particularly useful if SAS©/CONNECT is unavailable for PROC MIGRATE. PROC CPORT supports datasets and catalogs, but not all SAS© views. Transport files must be transferred in binary mode. In case of encoding changes, PROC CIMPORT's EXTENDVAR= option or the CVP engine can prevent truncation.
Data Analysis

Type : CREATION_INTERNE


The examples use generic library paths ('library-path-1', 'library-path-2', 'c:\example', '/mydata/example') and transport files ('c:\myfiles\mytransfer', '/mydata/mytransfer'), implying that source data already exists. For standalone execution, these paths would need to be replaced with existing SAS libraries.

1 Code Block
PROC MIGRATE
Explanation :
This example uses the PROC MIGRATE procedure to migrate members of a SAS library. Migration allows taking advantage of features in a newer SAS version. This example does not require a SAS/CONNECT server, except in some specific cases. Files created in SAS for Windows are directly accessible in this session.
Copied!
1LIBNAME myfiles 'library-path-1';
2LIBNAME target 'library-path-2';
3PROC MIGRATE in=myfiles out=target;
4RUN;
2 Code Block
PROC COPY
Explanation :
This example uses the PROC COPY procedure to copy the entire 'myfiles' library to the 'target' library. No specific options are specified, meaning the default behavior (like CLONE) is used. Library members are assumed to have the same data representation and encoding as the current session.
Copied!
1LIBNAME myfiles 'library-path-1';
2LIBNAME target 'library-path-2';
3PROC COPY in=myfiles out=target;
4RUN;
3 Code Block
PROC CPORT
Explanation :
This step creates a transport file from the source library. The transport file 'mytransfer' is referenced by the fileref 'tranfile'. The PROC CPORT procedure supports datasets and catalogs, but not other member types (like SAS views).
Copied!
1LIBNAME SOURCE 'c:\example';
2filename tranfile 'c:\myfiles\mytransfer';
3PROC CPORT library=SOURCE file=tranfile;
4RUN;
4 Code Block
PROC CIMPORT
Explanation :
This step imports the library from the previously created transport file. The PROC CIMPORT procedure creates the 'target' library by importing the contents of the 'mytransfer' file. The transport file must be transferred in binary mode if a communication software like FTP is used.
Copied!
1LIBNAME target '/mydata/example';
2filename tranfile '/mydata/mytransfer';
3PROC CIMPORT library=target INFILE=tranfile;
4RUN;
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.

Related Documentation : Data Access

Sujet / Mot-cléLien vers la ressource
DOC FedSQL en/sampleCode/FEDSQL9D66
Banner
Expert Advice
Expert
Simon
Expert SAS et fondateur.
« When moving or upgrading data, choosing the right procedure is critical for data integrity. Use PROC MIGRATE as your primary tool for upgrading libraries to newer SAS versions, as it preserves specialized attributes that a simple copy might lose. If you are moving data across different operating environments or encodings, prioritize the CPORT and CIMPORT sequence to ensure compatibility, and always use the CVP (Character Variable Padding) engine to prevent data truncation during encoding shifts. Avoid using operating system file utilities (like Windows Explorer or Linux cp), as these can corrupt SAS-specific file structures and catalogs. »