现在的位置: 首页 > 数据库 > 正文

PROC SQL中的逻辑判别和描述性统计函数

2018年10月21日 数据库 ⁄ 共 659字 ⁄ 字号 评论关闭

1.逻辑表达:>,<,!=,....

*data step;
data class_flags;
   set sashelp.class;
   tall = (height > 60);
   male = (sex = 'M');
   female = (sex = 'F');
run;
*proc sql;
proc sql;
   select name, 
          (height > 60) as tall, 
          (sex = 'M') as male, 
          (sex = 'F') as female
   from sashelp.class;
quit;

2.描述性统计函数sum(),mean(),....

proc sql;
   select sex, 
          max(height) as max_ht, 
          mean(weight) as mean_wt
   from sashelp.class
   group by sex;
quit;

proc sql;
   select age, 
          max(height*height/weight) as max_body_mass_index
   from sashelp.class
   group by age;
quit;

3.联合使用

proc sql;
   select max(height > 60) as any_tall, 
          mean(weight > 100) as pct_heavy,
          sum(gender = 'F') as num_female
   from sashelp.class;
quit;

 

proc sql;
   select sex,
          max(height > 60) as any_tall, mean(weight > 100) as pct_heavy
   from sashelp.class
   group by sex;
quit;

 

抱歉!评论已关闭.