turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Calculating Differences from Mean and Median

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-08-2016 11:12 AM

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!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Cloudrunner

06-08-2016 11:29 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

06-08-2016 12:54 PM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Cloudrunner

06-08-2016 02:10 PM

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;
```