码迷,mamicode.com
首页 > 其他好文 > 详细

SAS--chapter4

时间:2019-09-29 20:19:36      阅读:87      评论:0      收藏:0      [点我收藏+]

标签:print   har   and   永久   data   note   libname   strong   技术   

 

libname clinic D:\SAS; 
data clinic.admitfee;
  set sasueser.admit;
run;

proc sort data
=clinic.admitfee out=admit; /*proc 排序 排谁 输出到哪lib.name*/ by age; run;
proc print data
=admit label; /*打印 打谁 label?*/ var age height weight fee; /*变量 1 2 3 4 */ label fee=admission fee; /* 更换变量名*/ run;
proc print data
=admit noobs; /*no obs 取消显示observations*/ var age height; where age>30; /*where 给变量指定一个条件*/ run; /*character必须要加引号,区分大小写*/
proc print data=admit; id id; /*id 用后面的变量(可以不是一个)取代obs*/ run; /*当id后面的变量 和 var 后面的重复,那么这个变量会出现2次*/
data work.admit2; *创建数据集名称,位置; set sasuser.All; *引用该数据集; run;
ods listing; proc print data
=work.admit2; where location contains all; *变量location中contains all 子字符串的观察单位; run;
*contains 可以用 ? 代替; proc print data=admit; where age>30 and age<50; *逻辑关系 AND or & , OR or |; run;
proc print data
=admit; where age<30 or( age>50 and sex=M); *逻辑关系 AND or & , OR or |; run;
PROC PRINT DATA
=ADMIT; WHERE ACTLEVEL IN (LOW,MOD); * in 使得表达简洁; run;
proc sort data
=clinic.admit out=wdadmit; by weight age; *根据先weight后age排序,默认升序; run;
proc print data
=wdadmit; run;
proc sort data
=clinic.admit out=dwdadmit; by descending weight descending age; *降序 run; proc print data=dwdadmit; run;
proc print data
=admit; var name age height weight fee; where actlevel=LOW; sum fee; * 给变量求和,并创建新的一行; run;

proc sort data=clinic.admit out=admit;
  by actlevel;
run;
proc print data=admit;
  sum fee;
by actlevel; *按照分类变量求和,必须现根据该分类变量排序;
run;

proc sort data=clinic.admit out=admit;
by actlevel; 
run;


proc print data=admit;
sum fee;
by actlevel; *按照分类变量求和,必须现根据该分类变量排序;
run;


proc print data=admit;
sum fee;
by actlevel; *使用by 和 id联合使用,自定义layout,考虑id的作用;
id actlevel;
run;


proc print data=admit;
sum fee;
by actlevel; 
id actlevel;
pageby actlevel; *pageby后面的变量,必须在by中被指定;
run;
proc print data=admit double; *两倍行距;
sum fee;
run;


title1 ‘Heart Rates for Patients with‘; *数字可以说是1-10;
title11 ‘Increased Stress Tolerance Levels‘;
proc print data=admit;
run;


footnote1 ‘Data from Treadmill Tests‘;
footnote3 ‘1st Quarter Admissions‘;
proc print data=admit;
run;


title; *取消title和footnote;
footnote; *默认的title是SAS程序;
proc print data=admit;
run;


proc print data=admit label ; *临时的给变量名加label;
label fee=‘total fee‘; * ‘total fee‘n =‘fee‘ 有空格的情况;
run;
proc print data=admit label;
label fee=‘total fee‘ sex=‘gender‘; 
run;  

 

proc print data=clinic.admit;
var actlevel fee;
where actlevel=HIGH;
format fee dollar4.; *format 临时的改变数据的显示格式;
run;
proc print data=clinic.admit;
var actlevel fee;
where actlevel=HIGH;
format fee 5.2;
run;

 

技术图片

 

 

 永久的修改这些变量

data clinic.admit;
set sasuser.admit;
label fee=‘tatal fee‘;
run;


proc print dara=clinic.admit label;  *!!!print 时仍需要label;
run;

 

proc print data=admit split=‘*‘;
label fee=‘f*e*e‘;                *将变量名按照特殊的格式分开;
run;

label \double\noobs 需要在print里

proc sort  out

by

SAS--chapter4

标签:print   har   and   永久   data   note   libname   strong   技术   

原文地址:https://www.cnblogs.com/super-yb/p/11609357.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!