为了账号安全,请及时绑定邮箱和手机立即绑定

SAS Proc Means

标签:
大数据

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! 😇

点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消