楼主: fallleafsean
3707 11

用SAS修改txt文本 [推广有奖]

11
fallleafsean 发表于 2013-1-9 20:40:31
fallleafsean 发表于 2013-1-9 10:00
非常感谢~
%macro checknobs(dsn);
data _null_;
if nobs=0 then do;
call symput(“obscount”,”0″);
file print notitles;
put “there are no observations in &dsn”;
end;
else call symput(“obscount”,put(nobs,best12.));
stop;
set &dsn nobs=nobs;
run;
%if &obscount >0 %then %do;
proc print data=&dsn(obs=10);
title1 “a few observations from &dsn”;
run;
%end;
%mend checknobs;
%checknobs(SASHELP.CLASS)
%checknobs(SASHELP.DPLOG)
关于”编译“和“执行”的问题
这是网上查到的crackman的关于空集判断的宏程序,我试了下如果不加stop确实会出错,为什么会出现这个问题呢?

12
pobel 在职认证  发表于 2013-1-9 20:55:15
fallleafsean 发表于 2013-1-9 20:40
%macro checknobs(dsn);
data _null_;
if nobs=0 then do;
不加stop应该不会有错误。
这里加stop的原因是没有必要去执行set语句。

比如sashelp.class有19条记录,在执行set语句之前这个data步的目的就已经达到了,所以就没有必要去一条条读class的数据了。 没有stop语句的话,在读每一条记录之前,set前的语句就会执行一次,和执行一次的效果是一样的。
已有 1 人评分学术水平 热心指数 信用等级 收起 理由
fallleafsean + 1 + 1 + 1 分析的有道理

总评分: 学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

和谐拯救危机

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-5 22:55