我是SAS基地的新手,我正在尝试添加一行,说明当nobs = 0时所有ID都已转移。这是我在Alex给我的内容中添加的ID打印ID& #39;数据集中有任何数据集workgo.recds_not_processed。我添加了nobs = 0条件,但是当它们出现时它没有发送ID。
data _null_;
length id_list $ 3000;
retain id_list '';
file mymail;
SET set workgo.recds_not_processed nobs = nobs end = eof;
IF nobs = 0 then PUT "All ID's transferred successfully";
else if _n_ = 1 then do;
put 'Number of records not processed=' nobs;
put 'The IDs are:';
end;
/* Print the IDs in chunks */
if length(strip(id_list)) > 2000 then do;
put id_list;
call missing(id_list);
end;
call catx(', ', id_list, id);
if eof then put id_list;
run;
答案 0 :(得分:1)
你几乎就在那里 - Joe发现了无法比拟的end
和我指出的双set
是阻止你的代码工作的唯一明显错误。
处理空数据集时没有输出的原因是SAS在尝试从set语句中读取记录时终止数据步骤,并且没有剩余可读取。一种解决方案是在set语句之前移动空数据集逻辑。
此外,您可以在不使用retain
和call catx
的情况下通过在put语句中使用双尾@@
从多个观察中重复写入同一行来获得所需的结果输入数据集:
data recds_not_processed;
do id=1 to 20;
output;
end;
run;
data _null_;
/*nobs is populated when the data step is compiled, so we can use it before the set statement first executes*/
IF nobs=0 then
do;
PUT "All IDs transferred successfully";
stop;
end;
/*We have to put the set statement after the no-records logic because SAS terminates the data step after trying to read a record when there are none remaining.*/
SET recds_not_processed nobs=nobs end=eof;
if _n_=1 then
do;
put 'Number of records not processed=' nobs;
put 'The IDs are:';
end;
/* Print the IDs in chunks */
if eof or mod(_N_, 5)=0 then
put id;
else
put id +(-1) ', ' @@;
run;