BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Rhodochrosite | Level 12

Hello Experts,

 

Is it possible in proc princomp to show the labels ?

 

Capture d’écran 2026-02-23 150140.png

Thank you for your help!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The SAS documentation does not show an option to display labels of the variables.

--
Paige Miller

View solution in original post

10 REPLIES 10
Kathryn_SAS
SAS Employee

From the PROC PRINCOMP documentation:

The ID statement labels observations by using values from the first ID variable in the principal component score plot.

If you have additional questions, please include the code you are currently using.

PaigeMiller
Diamond | Level 26

@SASdevAnneMarie wrote:

 

Is it possible in proc princomp to show the labels ?


Do you mean labels of the variables (which is what I think you are asking), or labels on the observations? Please state clearly what you mean.

 

If you mean labels on the variables, then the documentation does not list any option to display the labels on the plots. If you mean labels on the observations, @Kathryn_SAS has answered that.

--
Paige Miller
SASdevAnneMarie
Rhodochrosite | Level 12
Thank you. I would like to display the labels of variables.
PaigeMiller
Diamond | Level 26

The SAS documentation does not show an option to display labels of the variables.

--
Paige Miller
sbxkoenk
SAS Super FREQ

Rick is labeling observations AND variables!
@Rick_SAS 

Comparing flavor characteristics of Scotch whiskies: A principal component analysis

PaigeMiller
Diamond | Level 26

@sbxkoenk wrote:

Rick is labeling observations AND variables!


Sorry, no, those are variable names. They are not variable labels. 

 

Now Rick was smart and chose variable names that are easily understood, rather than something like this title: tvar=volcsum_t, which is something that I actually saw on someone's plot. Although I would note that some applications may not have such easy to understand variable names ... which is why labels are needed in some reports and such for those applications.

 

So the answer to @SASdevAnneMarie would be to rename the variables if possible.

--
Paige Miller
sbxkoenk
SAS Super FREQ

@PaigeMiller 

You're right. I missed the point (labels of variables and not names of variables).

 

Koen

SASdevAnneMarie
Rhodochrosite | Level 12
Thank you!
Rick_SAS
SAS Super FREQ

It's hard to tell from the image you posted, but it looks like you want a "Pattern Plot" (somtimes called a "loadings Plot").  Try imitating this code:

ods graphics on;ods graphics on;
proc princomp data=sashelp.iris plots=pattern(vector circles=25 50 75 100);
var _numeric_;
run;

If you need a refresher on how to interpret a pattern plot, see https://blogs.sas.com/content/iml/2019/11/04/interpret-graphs-principal-components.html

 

Rick_SAS
SAS Super FREQ

Ah! Thanks @PaigeMiller for pointing out that the OP wants to plot variable LABELS, not names.  I agree that there is no built-in option to make the ODS graphics from PROC PRINTCOMP use labels. The OP will need to use the VALIDVARNAME=ANY option to rename variables as n-literals. Here is an example:

 

/* What are the labels for the variables? */
proc contents data=sashelp.iris varnum;
   ods select Position;
run;

/* create a copy of the data and use VALIDVARNAME=ANY to rename the 
   variables to their label values */
option validvarname=ANY;
data Iris;
   set sashelp.iris;
   rename 
   PetalLength = 'Petal Length (mm)'n
   PetalWidth  = 'Petal Width (mm)'n
   SepalLength = 'Sepal Length (mm)'n
   SepalWidth  = 'Sepal Width (mm)'n;
run;

/* run PCA on the new data set */
ods graphics on;
proc princomp data=Iris
     plots=pattern(vector circles=25 50 75 100);
var _numeric_;
run;

PatternPlot30.png

I assume this is a one-time task, but if you need to incorporate it into a process, you can write a macro that uses the output of PROC CONTENTS tp automatically create the new variable (with long n-literal names) as copies of the original variables. See 35973 - Display variable labels instead of variable names in procedure results

 

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore Now →
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 719 views
  • 11 likes
  • 5 in conversation