Hello Experts,
Is it possible in proc princomp to show the labels ?
Thank you for your help!
The SAS documentation does not show an option to display labels of the variables.
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.
@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.
The SAS documentation does not show an option to display labels of the variables.
@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.
You're right. I missed the point (labels of variables and not names of variables).
Koen
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
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;
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
Dive into keynotes, announcements and breakthroughs on demand.
Explore Now →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.
Ready to level-up your skills? Choose your own adventure.