PCA Procedure

Example 25.1 Analyzing Mean Temperatures of US Cities

(View the complete code for this example.)

This example analyzes mean daily temperatures of selected US cities in January and July. The following DATA step creates the data:

data mylib.Temperature;
   length Cityid $ 2;
   title 'Mean Temperature of Selected Cities in January and July';
   input City $1-15 January July;
   Cityid = substr(City,1,2);
   datalines;
Mobile          51.2 81.6
Phoenix         51.2 91.2
Little Rock     39.5 81.4
Sacramento      45.1 75.2
Denver          29.9 73.0

   ... more lines ...   

Cheyenne        26.6 69.1
;

The following statements invoke the PCA procedure, which requests a principal component analysis of these data and outputs the scores to an output data table. The Cityid variable is also included in the output data table (COPYVARS= Cityid).

title 'Mean Temperature of Selected Cities in January and July';
proc pca data=mylib.Temperature cov;
   var July January;
   output out=mylib.Scores copyVars=Cityid;
run;

Output 25.1.1 displays the PROC PCA output. The standard deviation of January (11.712) is higher than the standard deviation of July (5.128). The COV option in the PROC PCA statement requests that the principal components be computed from the covariance matrix. The total variance is 163.474. The first principal component accounts for about 94% of the total variance, and the second principal component accounts for only about 6%. The eigenvalues sum to the total variance.

Note that January receives a higher loading on Prin1 because it has a higher standard deviation than July. Also note that the PCA procedure calculates the scores by using the centered variables rather than the standardized variables.

Output 25.1.1: Results of Principal Component Analysis

Mean Temperature of Selected Cities in January and July

The PCA Procedure

Model Information
Data SourceTEMPERATURE
Component Extraction MethodEigenvalue Decomposition

Number of Variables2
Number of Principal Components2

Number of Observations Read64
Number of Observations Used64

Simple Statistics
VariableMeanStandard
Deviation
July75.607815.12762
January32.0953111.71243

Covariance Matrix
VariableJulyJanuary
July26.2924846.82829
January46.82829137.18109

Total Variance163.47356647

Eigenvalues of the Covariance Matrix
 EigenvalueDifferenceProportionCumulative
1154.310607145.1476470.94390.9439
29.162960 0.05611.0000

Eigenvectors
VariablePrin1Prin2
July0.34353-0.93914
January0.939140.34353


Last updated: June 22, 2026