楼主: l6397
3653 13

急盼[求助]前辈:数据集的查找并接 [推广有奖]

11
icepolice 发表于 2008-3-16 08:53:00

wolfcrying,


就你关于我那笨招的意见,
我想用宏来解决, 可是想不出来, 你有办法吗?望不吝赐教,多谢!

12
wolfcrying 发表于 2008-3-16 11:04:00

你精简代码的思路是很好的。如果能加上一个判断条件,在append之前将final初始化就更好了,否则log要报错。还有就是不应该直接 data mc;这样会将原来的mc数据集覆盖的,所以你要加个前缀什么的,不影响原数据集。 这样更改之后,data _null_已无必要保留,删去!

 data nonexist;
  set jh;
  retain ini 0;
  if exist(mc) then do;
  call execute("data _temp"||compress(mc)||";");
  call execute("set "||compress(mc)||";");
  call execute("sl="||sl||";");
  call execute("mc='"||mc||"';");
  call execute("run;");

  ini+1;
  if ini=1 then   call execute("data final;set _temp"||compress(mc)||"run;");
             else   call execute ("proc append base=final data= _temp"||compress(mc)||"; run; ");
  end;

  else do; message="Dataset: "||comress(mc)||"not exist, Please Check it.";
        keep mc warning;
        output nonexist;
  end;
run;

解决这类数据集的变量值去控制其他数据集,用call execute是最简洁有效的,只是call execute对初学者来说,不容易理解和掌握。用宏也可以实现,只是要创建一系列的动态宏变量,比如&&x&i..,比较复杂,不推荐使用

[此贴子已经被作者于2008-3-16 11:13:04编辑过]

13
icepolice 发表于 2008-3-16 13:05:00


你的建议很对, 看得出你的经验很多。以后多向你学习。 我运行了你的程序, 发现有一句缺了一个";"  还有一个compress 拼错了。我把正确的Code 写在下面了. 再次谢谢你!




  data nonexist;
  set jh;
  retain ini 0;
  if exist(mc) then do;
  call execute("data _temp"||compress(mc)||";");
  call execute("set "||compress(mc)||";");
  call execute("sl="||sl||";");
  call execute("mc='"||mc||"';");
  call execute("run;");

  ini+1;
  if ini=1 then   call execute("data final;set _temp"||compress(mc)||"; run;");
             else   call execute ("proc append base=final data= _temp"||compress(mc)||"; run; ");
  end;

  else do; message="Dataset: "||compress(mc)||"not exist, Please Check it.";
        keep mc warning;
        output nonexist;
  end;
run;

14
l6397 发表于 2008-3-16 15:06:00

真的非常感谢各位前辈!

虽然我是在自学,但我感觉就象在一个大课堂,有这么多老师教导,谢谢您们!!

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

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