楼主: dxystata
16082 4

如何判断一个数据集为空或0个观测值 [推广有奖]

版主

已卖:302份资源

大师

37%

还不是VIP/贵宾

-

TA的文库  其他...

Software

中英文Ebook

R学习

威望
2
论坛币
183395 个
通用积分
15333.1475
学术水平
208 点
热心指数
271 点
信用等级
174 点
经验
298627 点
帖子
5586
精华
1
在线时间
13632 小时
注册时间
2006-6-21
最后登录
2025-12-22

初级学术勋章 初级热心勋章 中级热心勋章 初级信用勋章

楼主
dxystata 发表于 2013-12-8 11:13:41 |AI写论文
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
关键词:观测值 数据集 Procedure Macro means 如何

本帖被以下文库推荐

沙发
Eternal0601 发表于 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

藤椅
webgu 发表于 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)
已有 1 人评分经验 学术水平 热心指数 收起 理由
dxystata + 40 + 1 + 1 观点有启发

总评分: 经验 + 40  学术水平 + 1  热心指数 + 1   查看全部评分

SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

板凳
zw612003 发表于 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为什么可以不加''?

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

data test;
%sysfunc 是在宏程序的环境里,不需要引号把字符 引起来。
SAS资源
1. SAS 微信:StatsThinking
2. SAS QQ群:348941365

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

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