继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

SAS Proc Means

乌然娅措
关注TA
已关注
手记 64
粉丝 21
获赞 12

SAS Day 27: Proc Means

We use Statistical summary to demonstrate the mean, median, max, min, Q1, Q3… 
In SAS we can either use Proc Means or Proc Univariate to achieve the goals.
Today we will introduce how to generate statistical summary using Proc Means.

Basic Syntax:

proc means data= dummy noprint;
var age; /*Any continuous variable: age, weight, height*/
where &cond; /*Subset the population, ex: Safety population="Y"*/
output out=temp1 n=n mean=mean std=std min=min median=median max=max q1=q1 q3=q3; 
/*Any statistical meausures we need to present*/
run;

The above step will generate the basic summary, we can manipulate with the format a little bit so we can present the data in a nice way.

[caption id=“attachment_1885” align=“alignnone” width=“560”]image

95839 / Pixabay[/caption]

Basic Syntax:

data test;
length col $100.;
set temp1;
  ord=0.5; label="Summary Statistics of Age"; output;
  ord=1; label=' N'; col=strip(put(n,best8.)); output;
  ord=2; label=' Mean'; col=strip(put(mean,8.1)); output;
  ord=3; label=' STDEV'; col=strip(put(std,8.2)); output;
  ord=4; label=' Median'; col=strip(put(median,8.1)); output;
  *ord=4.5; hd=' Q1, Q3'; col1=strip(put(q1,8.1))||', '||strip(put(q3,8.1)); output;
  ord=5; label=' Min, Max'; col=strip(put(min,8.1))||', '||strip(put(max,8.1)); output;
  keep  ord label col;
run;

Note: we can tailor the decimal points “8.1” or “8.2” based on the output requirement.

Now, finally, we can demonstrate our data to the audience.

image

Bonus Macro Coding:

Most of the time we need to develop Statistical summary for many continuous variables, such as Age, Height, Weight, Disease Lines or and so on. Therefore, it would be extremely useful if we modify the previous code a little to create a Macro Proc Means.

Basic Syntax:

%macro mean(var=, out=,  cond=);
proc means data=test noprint;
var &var;
where &cond;

output out=temp n=n mean=mean std=std min=min median=median max=max q1=q1 q3=q3;
run;

data &out;
 set temp;
  ord=0.5; label="Summary Statistics of Age"; output;
  ord=1; label=' N'; col=strip(put(n,best8.)); output;
  ord=2; label=' Mean'; col=strip(put(mean,8.1)); output;
  ord=3; label=' STDEV'; col=strip(put(std,8.2)); output;
  ord=4; label=' Median'; col=strip(put(median,8.1)); output;
 *ord=4.5; hd='  Q1, Q3'; col1=strip(put(q1,best8.)))||', '||strip(put(q3,best8.))); output;
  ord=5; label=' Min, Max'; col=strip(put(min,8.1))||', '||strip(put(max,8.1)); output;
  keep  ord label col;
run;
%mend;

Now we can just use the macro to call all the desired variables.

%mean (var=height, out=age, cond= safety=“y”)

Happy Studying! 😇

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP

相关阅读

SAS Proc Univariate