BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mikiduta
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

9 REPLIES 9
art297
Opal | Level 21

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

 

mikiduta
Fluorite | Level 6

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!

Reeza
Super User

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;
mikiduta
Fluorite | Level 6

thank you so much!  best regards!

Reeza
Super User

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;

 

mikiduta
Fluorite | Level 6

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

mikiduta
Fluorite | Level 6

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:)

Reeza
Super User

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?

mikiduta
Fluorite | Level 6

Thanks, I will start a new question.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register 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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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