BookmarkSubscribeRSS Feed
Cloudrunner
Calcite | Level 5

I am working on an assignment that asks to calculate:

1: The difference from the Mean (for each variable) as a raw difference and a percent difference 

2: The difference from the Median (for each variable) as a raw difference and a percent difference 

 

I know I should start with calculating the mean/median for each variable, but is there a formula to calculate the difference and percent difference? 

 

 

Thanks!

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

Probably the easiest method is:

http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a000146729.htm

You can then merge the mean back onto your data, and subtract the value from the calculated mean to get offset.

Cloudrunner
Calcite | Level 5

Thanks for the reply. Could I also create a new dataset with the mean, and create new variables for the raw difference and percent difference using if/then statements to specify them? 

 

 

 

Reeza
Super User

Why do you need if/then statements?

 

Here's code to get you started. You can calculate the percent difference and other statistics from here. 

 

proc means data=sashelp.class;
var weight;
output out=summary_stats mean=weight_avg median=weight_median;
run;

data want;
set sashelp.class;

if _n_ = 1 then set summary_stats (keep = weight:);

diff_mean = weight - weight_avg;
diff_median = weight - weight_median;

run;

proc print data=want;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 3174 views
  • 4 likes
  • 3 in conversation