全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
15961 4
2013-12-08
悬赏 20 个论坛币 已解决
NOTE: 数据集 WORK.TEMP2 有 0 个观测和 8 个变量。
NOTE: “PROCEDURE MEANS”所用时间(总处理时间):
      实际时间          0.02 秒
      CPU 时间          0.03 秒

如何判断一个数据集为空或0个观测值以及如何在macro写条件语句?谢谢!

最佳答案

Eternal0601 查看完整内容

data _null_; if 0 then set sashelp.class nobs=nobs; call symputx('nobs',nobs); stop; run; %macro test; %if &nobs=0 %then %put empty; %else %put not empty; %mend test; %test
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2013-12-8 11:13:42

data _null_;
        if 0 then set sashelp.class nobs=nobs;
        call symputx('nobs',nobs);
        stop;
run;

%macro test;
%if &nobs=0 %then %put empty;
%else %put not empty;
%mend test;

%test
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-8 14:31:36
*definition of a simple macro;
%macro  datasetcheck(dsname);
     %global  nobs;
         %let  dsid=%sysfunc(open(&dsname));
          %if  &dsid %then
            %do;
                     %let nobs=%sysfunc(attrn(&dsid,nobs));
                         %let rc=%sysfunc(close(&dsid));
                         %put  The dataset :&dsname has &nobs of observation ;
                %end;
      %else   %put open  dataset &dsname failed %sysfunc(sysmsg()) ;
%mend;

*a demo;
%datasetcheck(sashelp.class)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-8 19:55:43
webgu 发表于 2013-12-8 14:31
*definition of a simple macro;
%macro  datasetcheck(dsname);
     %global  nobs;
%let nobs=%sysfunc(attrn(&dsid,nobs));

data test;
rc = open('sashelp.class');
test = attrn(rc,'nobs');
run;

红色的code为什么可以不加''?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2013-12-9 13:03:27
zw612003 发表于 2013-12-8 19:55
%let nobs=%sysfunc(attrn(&dsid,nobs));

data test;
%sysfunc 是在宏程序的环境里,不需要引号把字符 引起来。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群