BookmarkSubscribeRSS Feed
jtambure
Fluorite | Level 6

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;

6 REPLIES 6
Astounding
PROC Star

Would PROC STANDARD be the right tool for the job?

Reeza
Super User

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;

jtambure
Fluorite | Level 6

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!

Astounding
PROC Star

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.

jtambure
Fluorite | Level 6

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.

Astounding
PROC Star

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 2329 views
  • 6 likes
  • 3 in conversation