DATA Step, Macro, Functions and more

how to rename zscores for a dataset with many variables

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 11
Accepted Solution

how to rename zscores for a dataset with many variables

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!


Accepted Solutions
Solution
‎02-17-2017 03:25 PM
Super User
Posts: 17,829

Re: how to rename zscores for a dataset with many variables

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;

View solution in original post


All Replies
PROC Star
Posts: 7,363

Re: how to rename zscores for a dataset with many variables

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

 

Occasional Contributor
Posts: 11

Re: how to rename zscores for a dataset with many variables

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!

Solution
‎02-17-2017 03:25 PM
Super User
Posts: 17,829

Re: how to rename zscores for a dataset with many variables

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;
Occasional Contributor
Posts: 11

Re: how to rename zscores for a dataset with many variables

thank you so much!  best regards!

Super User
Posts: 17,829

Re: how to rename zscores for a dataset with many variables

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;

 

Occasional Contributor
Posts: 11

Re: how to rename zscores for a dataset with many variables

Oh, thank you so much! This is very helpful!

Occasional Contributor
Posts: 11

Re: how to rename zscores for a dataset with many variables

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 againSmiley Happy

Super User
Posts: 17,829

Re: how to rename zscores for a dataset with many variables

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?

Occasional Contributor
Posts: 11

Re: how to rename zscores for a dataset with many variables

Thanks, I will start a new question.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 9 replies
  • 134 views
  • 4 likes
  • 3 in conversation