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?
Probably the easiest method is:
You can then merge the mean back onto your data, and subtract the value from the calculated mean to get offset.
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.