05-14-2012 12:03 PM
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)
05-14-2012 02:09 PM
I think Astounding is referring to PROC STDIZE to accomplish this.
Another method, but still more manual is using proc sql
create table new_data as
select *, weight-avg(weight) as centered_weight_by_sex
group by sex;
05-16-2012 01:53 PM
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.
05-16-2012 02:04 PM
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.
05-16-2012 02:16 PM
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.