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/
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 秒