Examples: Use a SAS Engine to Process SAS Data
- Example: Assign the V9 Engine in a LIBNAME Statement
- Example: Assign the SPD Engine in a LIBNAME Statement
- Example: Read and Write SAS Data in Hadoop by Using the SPD Engine
- Example: Avoid Truncation by Using the CVP Engine with the V9 Engine
- Example: Load a SAS Data Set to a CAS Server
Example: Assign the V9 Engine in a LIBNAME Statement
Example Code
This library assignment specifies the V9 engine.
libname myfiles v9 'library-path'; /*1*/
data myfiles.myclass; /*2*/
set sashelp.class;
run;
-
The LIBNAME statement assigns the
myfileslibref and the V9 engine to the location of a library. Substitute the location of your library forlibrary-path. The location must already exist and must be accessible by the SAS Compute Server. -
The DATA step creates the
myclassdata set in themyfileslibrary by copying theclassdata set from thesashelplibrary.
SAS Log Showing a Successful V9 Library Assignment
1 libname myfiles v9 'library-path';
NOTE: Libref MYFILES was successfully assigned as follows:
Engine: V9
Physical Name: library-path
2 !
3 data myfiles.myclass;
4 set sashelp.class;
5 run;
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set MYFILES.MYCLASS has 19 observations and 5 variables.
Key Ideas
|
Example: Assign the SPD Engine in a LIBNAME Statement
Example Code
The following LIBNAME statement for the SPD Engine is very similar to a LIBNAME statement for the V9 engine.
libname mylib spde 'library-path' /*1*/
datapath=('path-for-data-partitions') /*2*/
indexpath=('path-for-indexes'); /*3*/
-
This portion of the LIBNAME statement assigns the
myliblibref and the SPD Engine to a primary path name. The first (and usually only) metadata file for a data set is always stored in the library’s primary path. -
Optionally, you can assign one or more path names in the DATAPATH= option to store data partitions. Otherwise, the data partition files are stored in the primary path.
-
Optionally, you can assign one or more path names in the INDEXPATH= option to store index files. Otherwise, the index files are stored in the primary path.
SAS Log Showing a Successful SPD Engine Library Assignment
1 libname mylib spde 'library-path'
2 datapath=('path-for-data-partitions')
3 indexpath=('path-for-indexes');
NOTE: Libref MYLIB was successfully assigned as follows:
Engine: SPDE
Physical Name: library-path
3 !
Key Ideas
|
Example: Read and Write SAS Data in Hadoop by Using the SPD Engine
Example Code
The following example assigns a Base SAS library to a Hadoop cluster.
options; /*1*/
options;
libname mydata spde '/data/abcdef' hdfs=yes accelwhere=yes; /*2*/
-
The SET= system option defines environment variables for Hadoop. If these environment variables are already set (for example, during configuration), do not submit these lines of code. If these environment variables are not correctly set, then the LIBNAME statement produces errors in the SAS log.
-
The LIBNAME statement assigns the
mydatalibref to the SPD Engine and a directory in the Hadoop cluster. The HDFS=YES argument specifies to connect to the Hadoop cluster that is defined in the Hadoop cluster configuration files. The ACCELWHERE=YES option requests that data subsetting be performed by a MapReduce program in the Hadoop cluster.
Key Ideas
|
Example: Avoid Truncation by Using the CVP Engine with the V9 Engine
Example Code
To run this example,
first create a data set named myclass as
in Example: Assign the V9 Engine in a LIBNAME Statement. Run PROC CONTENTS to see the length
of the variables:
libname myfiles v9 'library-path-1';
proc contents data=myfiles.myclass;
run;
In the PROC CONTENTS output, notice the two character variables. Name has a length of 8, and Sex has a length of 1.
PROC CONTENTS Showing Variable Lengths before Expansion

The example below uses the CVP engine with the V9 engine to expand the size of character variables. The CVP engine can help you avoid truncation if you copy a data set to an encoding that uses more bytes to represent the characters.
libname srclib cvp 'library-path-1' cvpengine=v9 cvpmult=2.5; /*1*/
libname target v9 'library-path-2'; /*2*/
proc copy in=srclib out=target; /*3*/
select myclass;
run;
proc contents data=target.myclass; /*4*/
run;
-
This LIBNAME statement assigns the
srcliblibrary to the CVP engine and the location of the data that you want to copy. The CVPENGINE= option specifies the V9 engine as the underlying engine to process the data. The CVPMULT= option specifies a multiplication factor of 2.5 to expand all character variables. If this option is not specified, the CVP engine automatically chooses a multiplier value. -
This LIBNAME statement assigns the
targetlibrary to contain the copied data. -
The COPY procedure with SELECT statement copies the
myclassdata set to thetargetlibrary. During the copy, the CVP engine expands the character variable lengths 2.5 times larger. -
The CONTENTS procedure shows that the lengths of the character variables have been multiplied by 2.5:
For Name, 8 × 2.5 = 20.
For Sex, 1 × 2.5 = 2.5, which is 3 when rounded up to a whole number.
PROC CONTENTS Showing Variable Lengths after Expansion

Key Ideas
|
See Also
- SAS National Language Support (NLS): Reference Guide
- Compatibility and Migration in SAS V9 LIBNAME Engine: Reference
- COPY Procedure in Base SAS Procedures Guide
Example: Load a SAS Data Set to a CAS Server
Example Code
The following example uses the DATA step to load a SAS data set into memory as a SAS Cloud Analytic Services (CAS) table.
cas casauto host="cloud.example.com" port=5570; /*1*/
libname mycas cas; /*2*/
data mycas.cars (promote=yes); /*3*/
set sashelp.cars;
run;
proc contents data=mycas.cars; /*4*/
run;
-
The CAS statement starts a CAS session and specifies
casautoas the CAS session name. Use your connection information in the HOST= and PORT= options. -
The LIBNAME statement assigns the
mycaslibref to the CAS engine. The SESSREF= LIBNAME option is not specified, so the engine uses thecasautosession. -
The DATA step copies the SAS data set
sashelp.carsto the CAS session. The PROMOTE=YES data set option promotes the table with global scope. -
PROC CONTENTS shows the
mycas.carstable is available on the CAS server for the duration of the session. After data is loaded into memory, subsequent steps can process the data in memory. Loading and processing are done in separate steps.
Portion of PROC CONTENTS Output for mycas.cars

Key Ideas
|
See Also
- LIBNAME Statement: CAS Engine in SAS Cloud Analytic Services: User’s Guide
- The DATA Step and CAS in SAS Cloud Analytic Services: DATA Step Programming
- Example: Load SAS Data to CAS by Using the CASUTIL Procedure in SAS V9 LIBNAME Engine: Reference
- SAS Viya Platform Programming: Getting Started