Help using Base SAS procedures

Recoding to Center Variable Referencing Variable Mean

Reply
New Contributor
Posts: 4

Recoding to Center Variable Referencing Variable Mean

Many times, I create a new variable that transposes the responses of a variable to 'center' them. The only way that I know to do this so far, i need to run a proc univariate for the mean of the value then, in the data step, create the centered variable by referencing the output of the proc univariate. This seems like a lot of work that is not easily transferable between projects, or if the values of a mean change due to re-framing my sample. Additionally, I can only reference the mean to as many digits as SAS reports in the output.  Is there an easier way, perhaps by having a code that directly references the mean value of the responses to a variable?

An example of the code that I currently use:

proc univariate; var INCOME; run;

data NEWSET; set OLDSET;

centeredINCOME=INCOME - 1.58762368; (this number I reference from the output of proc univariate)

run;

Super User
Posts: 5,085

Re: Recoding to Center Variable Referencing Variable Mean

Would PROC STANDARD be the right tool for the job?

Super User
Posts: 17,840

Re: Recoding to Center Variable Referencing Variable Mean

I think Astounding is referring to PROC STDIZE to accomplish this.

Another method, but still more manual is using proc sql

proc sql;

    create table new_data as

    select *, weight-avg(weight) as centered_weight_by_sex

    from sashelp.class

    group by sex;

quit;

New Contributor
Posts: 4

Re: Recoding to Center Variable Referencing Variable Mean

I'm not familiar with the stdize procedure. Would this simply transpose the values so that the distribution is centered at a value of zero, or would it redistribute the variables to a regular distribution? I am looking simply to do the first, but not the second.

Thanks!

Super User
Posts: 5,085

Re: Recoding to Center Variable Referencing Variable Mean

jtambure,

I really meant PROC STANDARD.  Take a look at the online documentation.  I'm not a statistician, but I would guess this does what you want.  If you specify MEAN=0, and omit the STD= option it uses the standard deviation of the incoming variable.  But I really don't know if that means you get exactly what you are looking for.  You could always test it out and see.

Good luck.

New Contributor
Posts: 4

Re: Recoding to Center Variable Referencing Variable Mean

This does the same thing as my method, but it's no more easy and it requires me to create a new dataset in the process as well. Still, thanks. I'm sure that this might be useful, especially when I need to do this to more than one variable.

Super User
Posts: 5,085

Re: Recoding to Center Variable Referencing Variable Mean

It's also useful if you haven't already run a PROC UNIVARIATE.  You don't need to know the means ahead of time.

Ask a Question
Discussion stats
  • 6 replies
  • 733 views
  • 6 likes
  • 3 in conversation