PCA Procedure

PROC PCA Statement

  • PROC PCA <options>;

The PROC PCA statement invokes the PCA procedure. Optionally, it also identifies the input and output data sets, specifies the analyses to be performed, and controls displayed output. Table 3 summarizes the options available in the PROC PCA statement.

Table 3: PROC PCA Statement Options

Option Description
Specify Data Sets
DATA= Specifies the input data table
OUTSTAT= Specifies the output data table that contains various statistics
Specify Details of Analysis
COV Computes the principal components from the covariance matrix
GPU Uses graphics processing units (GPUs) to perform model computation
METHOD= Specifies the principal component extraction method to be used
N= Specifies the number of principal components to be computed
NOINT Omits the intercept from the model
PARPREFIX= Specifies a prefix for naming the residual variables
PREFIX= Specifies a prefix for naming the principal components
SINGULAR= Specifies the singularity criterion
STD Standardizes the principal component scores
VARDEF= Specifies the divisor to use for calculating variances and standard deviations
Specify ODS Graphics Details
PLOTS= Specifies options that control the details of the plots


The following list provides details about these options.

COVARIANCE
COV

computes the principal components from the covariance matrix. If you omit this option, the correlation matrix is analyzed. The COV option causes variables that have large variances to be more strongly associated with components that have large eigenvalues, and it causes variables that have small variances to be more strongly associated with components that have small eigenvalues. You should not specify this option unless the units in which the variables are measured are comparable or the variables are standardized in some way.

DATA=libref.data-table

names the input data table for PROC PCA to use. The default is the most recently created data table. libref.data-table is a two-level name, where

libref

refers to a collection of information that is defined in the LIBNAME statement and includes the library, which includes a path to the data, and a session identifier, which defaults to the active session but which can be explicitly defined in the LIBNAME statement. For more information about libref, see the section Using CAS Sessions and CAS Engine Librefs.

data-table

specifies the name of the input data table.

GPU

enables PROC PCA to use graphics processing units (GPUs) to perform model computation on GPU-equipped machines (one GPU is used on each machine). Currently the eigenvalue decomposition (EIG) method, the nonlinear iterative partial least squares (NIPALS) method, and the iterative method based on random projection (RANDOM) support this option. If you specify any other principal component extraction method or specify the BY statement or PARTIAL statement, the GPU option is ignored. If no GPU is available, the CPU is used to perform model computation.

PROC PCA uses CUDA 11.8, and the NVIDIA V100 and P100 GPUs are supported.[2]

METHOD=EIG | ITERGS<(iter-options)> | NIPALS<(nipals-options)> | RANDOM<(rand-options)>

specifies the principal component extraction method to be used. You can specify the following values:

EIG

requests eigenvalue decomposition.

ITERGS<(iter-options)>

requests the iterative method based on Gram-Schmidt orthogonalization (ITERGS) of Andrecut (2009). You can specify the following iter-options.

EPSILON=n

specifies the convergence criterion for the iterative method. By default, EPSILON=1E–12.

MAXITER=n

specifies the maximum number of iterations for the iterative method. By default, MAXITER=500.

NOCENTER

suppresses centering of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

NOSCALE

suppresses scaling of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

NIPALS<(nipals-options)>

requests the nonlinear iterative partial least squares (NIPALS) method. You can specify the following nipals-options.

EPSILON=n

specifies the convergence criterion for the iterative method. By default, EPSILON=1E–12.

MAXITER=n

specifies the maximum number of iterations for the iterative method. By default, MAXITER=500.

NOCENTER

suppresses centering of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

NOSCALE

suppresses scaling of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

RANDOM<(rand-options)>

requests the iterative method based on random projection (RANDOM) of Halko, Martinsson, and Tropp (2011). You can specify the following rand-options.

NITER=n

specifies the number of iterations. By default, NITER=1.

NOCENTER

suppresses centering of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

NOSCALE

suppresses scaling of the numeric variables to be analyzed. This option is useful if the analysis variables are already centered and scaled.

SEED=number

specifies an integer as the seed value for pseudorandom number generation. PROC PCA uses random values to initialize the Gaussian random projection matrix. If you do not specify this option or if number is less than or equal to 0, the seed is generated by reading the time of day from the computer’s clock. By default, SEED=0.

By default, METHOD=EIG. If you specify METHOD=ITERGS, METHOD=NIPALS, or METHOD=RANDOM, the following options in the PROC PCA statement are not supported: COV, NOINT, OUTSTAT=, PARPREFIX=, SINGULAR=, and STD.

N=number

specifies the number of principal components to be computed. If you specify METHOD=ITERGS, METHOD=NIPALS, or METHOD=EIG, the default is the number of variables. If you specify METHOD=RANDOM, the default is 1. The number must be an integer greater than or equal to 0. If N=0, the default is used.

NOINT

omits the intercept from the model. In other words, this option requests that the covariance or correlation matrix not be corrected for the mean. When you specify this option, the covariance matrix and, hence, the standard deviations are not corrected for the mean. If you want to obtain the standard deviations corrected for the mean, you can obtain them by using a procedure such as PROC MEANS in Base SAS.

OUTSTAT=libref.data-table

creates an output data table to contain means, standard deviations, number of observations, correlations or covariances, eigenvalues, and eigenvectors. libref.data-table is a two-level name, where libref refers to the library, and data-table specifies the name of the output data table. For more information about this two-level name, see the DATA= option and the section Using CAS Sessions and CAS Engine Librefs.

If you specify the COV option, the output data table contains a covariance matrix, and the corresponding _TYPE_ variable value is COV or UCOV, depending on the value of the NOINT option; otherwise, the output data table contains a correlation matrix, and the corresponding _TYPE_ variable value is CORR or UCORR, depending on the value of the NOINT option. If you specify the PARTIAL statement, the OUTSTAT= data table also contains R-squares.

For more information about the OUTSTAT= data table, see the section OUTSTAT= Data Table.

PLOTS <(global-plot-options)> <= plot-request <(options)>>
PLOTS <(global-plot-options)> <= (plot-request <(options)> <…plot-request <(options)>>)>

controls the plots that are produced through ODS Graphics. When you specify only one plot-request, you can omit the parentheses around it. Some examples follow:

plots
plots=none
plots=(eigen profile)
plots(unpack)=scree
plots=pattern(ncomp=3 circles=25 50 75 1)

ODS Graphics must be enabled before you can request plots. For example:

ods graphics on;
proc pca plots=all;
   var x1--x10;
run;
ods graphics off;

You must specify the PLOTS option in order for the PCA procedure to produce plots. If you do not specify a plot-request, PROC PCA produces the scree plot by default.

You can specify the following global-plot-options:

UNPACKPANEL
UNPACK

suppresses paneling in the scree plot. By default, multiple plots can appear in an output panel. Specify UNPACKPANEL if you want each plot to appear in a separate panel. You can specify PLOTS(UNPACKPANEL) to unpack the default plots. You can also specify UNPACKPANEL as a suboption of the SCREE option (such as PLOTS=SCREE(UNPACKPANEL)).

You can specify the following plot-requests:

ALL

produces all appropriate plots. You can specify other options along with ALL; for example, to request all plots and unpack only the scree plot, specify PLOTS=(ALL SCREE(UNPACKPANEL)).

EIGEN <( UNPACKPANEL )>
EIGENVALUE <( UNPACKPANEL )>
SCREE <( UNPACKPANEL )>

produces the scree plot of eigenvalues and proportion variance explained. By default, both plots appear in the same panel. Specify PLOTS= SCREE(UNPACKPANEL) if you want each plot to appear in a separate panel.

NONE

suppresses the display of all plots.

PATTERN <(pattern-options)>

produces the pairwise component pattern plots. Each variable is plotted as an observation whose coordinates are correlations between the variable and the two corresponding components in the plot. Use the NCOMP= option (for example, PLOTS=PATTERN(NCOMP=3)) as described in the following list to control the number of plots to display.

You can specify the following pattern-options:

CIRCLES <=number-list>

plots the variance percentage circles. For each number c (0 < c less-than-or-equal-to 1) that you specify, a (c times 100 percent-sign) variance circle is displayed. For each number c (c greater-than 1) that you specify, a c% variance circle is displayed. You can specify either CIRCLES=0.05 1 or CIRCLES=5 100 to display 5% and 100% variance circles. PLOTS=PATTERN(CIRCLES) and PLOTS=PATTERN(VECTOR) both display a unit circle (100% variance). By default, no circle is displayed when you specify PLOTS=PATTERN.

FLIP

interchanges (flips) the X-axis and Y-axis dimensions of the component pattern plots.

NCOMP=n

specifies the number of components n (greater-than-or-equal-to 2) to be plotted. The default is 5 or the total number of components m (greater-than-or-equal-to 2), whichever is smaller. If n greater-than m, NCOMP=m is used. Be aware that the number of plots (n times left-parenthesis n minus 1 right-parenthesis slash 2) that are produced grows quadratically when n increases.

VECTOR

plots the pattern in a vector form.

PATTERNPROFILE
PROFILE

produces the pattern profile plot. Each component has its own profile. The Y-axis value represents the correlation between the variable (corresponding to the X-axis value) and the profiled principal component.

PREFIX=name

specifies a prefix for naming the principal components. By default, the names are Prin1, Prin2, …, Prinn. If you specify PREFIX=Abc, the components are named Abc1, Abc2, Abc3, and so on. The number of characters in the prefix plus the number of digits required to designate the variables should not exceed the current name length that is defined by the VALIDVARNAME= system option.

PARPREFIX=name
PPREFIX=name
RPREFIX=name

specifies a prefix for naming the residual variables in the OUTSTAT= data table. By default, the prefix is R_. The number of characters in the prefix plus the maximum length of the variable names should not exceed the current name length that is defined by the VALIDVARNAME= system option.

SINGULAR=p
SING=p

specifies the singularity criterion, where 0 less-than sans-serif-italic p less-than 1. If a variable in a PARTIAL statement has an R-square as large as 1 minus sans-serif-italic p when predicted from the variables listed before it in the statement, the variable is assigned a standardized coefficient of 0. By default, SINGULAR=1E–8.

STANDARD
STD

standardizes the principal component scores in the OUT= data table in the OUTPUT statement to unit variance. If you omit this option, the scores have a variance equal to the corresponding eigenvalue. Note that this option has no effect on the eigenvalues themselves.

VARDEF=DF | N | WDF | WEIGHT | WGT

specifies the divisor to be used to calculate variances and standard deviations. By default, VARDEF=DF. The following table displays the values and associated divisors:

Table 4: continued

Value Divisor Formula
DF Error degrees of freedom n minus i (before partialing)
n minus p minus i (after partialing)
N Number of observations n
WEIGHT | WGT Sum of weights sigma-summation Underscript j equals 1 Overscript n Endscripts w Subscript j
WDF Sum of weights minus one left-parenthesis sigma-summation Underscript j equals 1 Overscript n Endscripts w Subscript j Baseline right-parenthesis minus i (before partialing)
left-parenthesis sigma-summation Underscript j equals 1 Overscript n Endscripts w Subscript j Baseline right-parenthesis minus p minus i (after partialing)


In the formulas for VARDEF=DF and VARDEF=WDF, p is the number of degrees of freedom of the variables in the PARTIAL statement, and i is 0 if you specify the NOINT option and 1 otherwise.



[2] The version information and corresponding GPU architectures depend on your SAS Viya version. Make sure that you are consulting the correct version of the documentation for your specific SAS Viya version.

Last updated: June 22, 2026