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

SAS Proc Univariate

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

SAS Day 36

In SAS Day 27, we showed using Proc Means to generate the statistical summaries for Continuous Variable such as (Age, BMI, Height, Weight). As an old idiom stated, “All Roads lead to Rome”.  Today we will introduce Proc Univariate to create the Summary Statistics.

[caption id=“attachment_2299” align=“alignnone” width=“750”]image

The_Double_A / Pixabay[/caption]

Task: Proc Univariate Sample for Statistical Summaries

Sample Dataset :

n: patient ID number

trt: treatment group

AGE: patient age

image

Output:

image

Sample Code:

macro uni(in=, var=, output=, sorter=); 

proc univariate data=&in noprint; 
  var &var; 
  class trt; 
  output out=x n=nn mean=meann  std=stdn median=mediann min=minn max=maxn q1=q1n q3=q3n ; 
run; 

data x; 
  set x; 
    length n $3\. mean $20\. median $25\. sd $8.3 q13$13\. mm $13\. ; 
    mean=put(meann,8.1); 
    median=put(mediann,3.) || "(" || put(minn,3.)||'-'||put(maxn,3.) ||")" ; 
    sd=put(stdn,8.2) ; 
    q13=put(q1n,6.1)||'-'||put(q3n,6.1); 
    mm=put(minn,6.1)||'-'||put(maxn,6.1); 
  n=put(nn,3.); 
  label n='   N' 
        mean='   Mean' 
        median='   Median'  
        sd="   Standard deviation" 
        q13="   25th-75th percentile" 
        mm='   Min-Max'; 
  keep n mean median mm q13 sd trt; 
run; 

proc transpose data=x out=&output(drop=_NAME_) prefix=col; 
  var n mean  median mm sd q13; 
  id trt; 
run; 

data &output; 
  length label $100\. col1 $40\. col2 $40\.  ; 
  set &output; 
  label=_LABEL_; 
  if label='   N' then sorter2=1; 
  else if label='   Mean' then sorter2=2; 
  else if label='   Median(range)' then sorter2=3; 
  else if label="   Standard deviation" then sorter2=4; 
  else if label="   25th-75th percentile" then sorter2=5; 
  else if label='   Min-Max' then sorter2=6; 
  sorter= &sorter; 
  keep sorter sorter2 label col:; 
proc sort; by sorter2; 
run; 
%mend uni; 

%uni(in=adsl, var=age, sorter= 1, output=a1);

Note: Special thanks to Alex Tian (Lipu), the sample code was originated by him. I modified the label and order along the time.
so maybe you could do your Mix and Match with this sample Proc Univariate code.

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