Hello everyone,
I have a question about creating zscores for many variables in a file with tens of variables. If I do this for a few variables everything is OK, as I can rename the variables as zscores and drop the redundant names (of the original variables). However, to do this with 50 variables is tedious. I was wondering if anyone can help me automatically assign zscore names that correspond to the original variables.
Thank you very much!
Use PROC STDIZE or STANDARD to standardize the variables - which is equivalent to taking the z score if you're using the distribution of the data. You can use variable lists/shortcuts in the VAR statement to simplify the process of listing the variables.
proc stdize data=have out=want method=std;
var LIST_VARS_HERE;
run;
Some example data, in the form of a datastep, would be helpful.
My initial guess is to use proc sql (using dictionary.columns) to write out all of the calculations and naming.
Do you have to do it for all of your numeric variables? It will also help to see the code you used to do the one example you mentioned.
Art, CEO, AnalystFinder.com
thank you so much! They are all numeric, I am using proc standard:
PROC STANDARD DATA= mydata MEAN=0 STD=1 OUT=zscoreswk;
VAR x1 x2 x3; run;
data quality.zscoreswk; set zscoreswk;
zx1=x1;
zx2=x2;
zx3=x3;
drop x1 x2 x3;
run;
I would like to be able to rename all the 50+ variables so that their new names include the original name zx1.....zx50.
Thanks! Have a nice afternoon!
Use PROC STDIZE or STANDARD to standardize the variables - which is equivalent to taking the z score if you're using the distribution of the data. You can use variable lists/shortcuts in the VAR statement to simplify the process of listing the variables.
proc stdize data=have out=want method=std;
var LIST_VARS_HERE;
run;
thank you so much! best regards!
If it's a series list you can rename it as:
set new_data (rename = (x1-x10=zx1-zx10));
data quality.zscoreswk;
set zscoreswk (rename = (x1-x3 = zx1-zx3));
run;
Oh, thank you so much! This is very helpful!
sorry to bother you again, how do I do this when my variables have various labels (e.g., x1=density of streets, x2= landuse mix etc), is there an easy way to convert all variables into new variables labelled x1....x50, so i could apply the method above? Thanks again:)
1. Start a new question, because this is different than your original
2. Please clarify your terminology, labels are used to show a descriptive information on the variable. A variable name is different.
Are you asking how to rename variables and keep the same labels?
Or are you saying your variables aren't labelled as series x1-x10?
Thanks, I will start a new question.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.