数学之路-sas备忘(12)

data student1;
input name$ age score;
datalines;
wangwu 29 68
lisi 30 85
wangxi 28 79
lixingxun 32 91
wufang 27 56
;
run;
data student;
set student1;
run;
data student2;
input name$ age score;
datalines;
wangwu 29 88
lisi 30 89
wangxi 28 85
lixingxun 32 93
wufang 27 76
;
run;
/*显示原数据集*/
proc print data=student;
title "原数据集";
run;
/*remove移除观测*/
data student1;
modify student1;
if score <80 then  remove;
run;
proc print data=student1;
title "remove";
run;
/*replace替换观测*/
data student;
modify student student2;
by name;
if score >85 then  replace;
run;
proc print data=student;
title "replace";

run;

本博客所有内容是原创,如果转载请注明来源

http://blog.csdn.net/myhaspl/





data sales sales1 sales2;
input id$ name$ price ;
if price >25 then output sales;
if price>20 then output sales1;
else output sales2;
cards;
1 x1 15.2
2 x2 29.3
3 x3 17.69
4 x4 20.12
;
proc print data=sales1;
title "sales1";
run;
proc print data=sales2;
title "sales2";
run;
proc print data=sales;
title "sales";
run;




data sales sales1 sales2;
input id$ name$ price ;
if price >20 ;*如果价格>20才写入数据集;
cards;
1 x1 15.2
2 x2 29.3
3 x3 17.69
4 x4 20.12
;
proc print data=sales;
title "sales";
run;



call调用call子程序

data sales ;
input id$ name$ price;
if price<20 then call sound(523,100);*如果价格低于20则声音报警;
cards;
1 x1 15.2
2 x2 29.3
3 x3 17.69
4 x4 20.12
5 x5 39.6
6 x6 15.4
;
proc print data=sales;
title "sales";
run;


第二个例子
data mydir;
call system("dir");*执行操作系统命令;
run;

 

list将记录写入sas日志

data sales ;
input id$ name$ price;
if price<20 then list;*如果价格低于20则输出到日志;
cards;
1 x1 15.2
2 x2 29.3
3 x3 17.69
4 x4 20.12
5 x5 39.6
6 x6 15.4
;
run;







337  data sales ;
338  input id$ name$ price;
339  if price<20 then list;*如果价格低于20则输出到日志;
340  cards;


RULE:      ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
341        1 x1 15.2
343        3 x3 17.69
346        6 x6 15.4
NOTE: 数据集 WORK.SALES 有 6 个观测和 3 个变量。
NOTE: “DATA 语句”所用时间(总处理时间):
      实际时间          0.03 秒
      CPU 时间          0.00 秒


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值