楼主: Tigflanker
2902 13

[问答] 请问是否有人知道:如何抓取当前程序中的某串字符 [推广有奖]

11
648189689 发表于 2013-9-15 21:09:57
不知你要干什么,我不知道

12
Tigflanker 发表于 2013-9-15 22:34:16
貌似朋友们都看不懂我想要什么,所以我干脆自己写了个半成品贴上来,若是得不到帮助,无妨。
这个毛坯宏是一小时写好的,只是想传达个意思:
在第一部分将宏预读,第二部分伴随着程序,运行本宏。
本宏的预期目的是:将第二部分程序中依照'proc printto print'的线索抓取路径'output-file'
大致步骤为:
1. 将第二部分程序保存到文件 2. 将文件infile到数据库 3. 按照find找到目标 4. 进一步抓取需要的东西。

毛坯宏,很多细节没有考虑到。log窗口%put出结果:output-file
  1. 1.首先将这个宏预读。
  2. %Macro Find_and_Get(what=);

  3. *1.Save the current program into a temp file under E:\;
  4. dm 'file "E:\Find_and_Get_temp.txt" replace';

  5. *2.Read the program into dataset;
  6. data Find_and_Get_temp;
  7.   infile "E:\Find_and_Get_temp.txt" delimiter=";";
  8.   input code $500. @@;
  9.   code=trim(code);
  10. run;

  11. *3.Find and Get it!;
  12. data _null;set Find_and_Get_temp;
  13. if find(code,"&what") and not find(code,"Find_and_Get");
  14. from=find(code,"'");to=find(code,"'",from+1);
  15. want=substr(code,from+1,to-from-1);
  16. call symputx('want',want);
  17. run;
  18. %put &want.;

  19. %Mend Find_and_Get;
复制代码
  1. 2.以下是需要抓取的实例,其最后一行是调用的本宏。
  2. %Macro some_example;
  3. proc means data=grade maxdec=3;
  4.   var Score             ;
  5.   class Status Year;
  6.   types () status*year;
  7.   title 'Final Exam Grades for Student Status and Year of Graduation';
  8. run;

  9. proc printto print='output-file';  *我希望运行本程序的同时,依照'proc printto print'的线索抓取到这个参数'output-file';
  10. run;
  11. %Mend;

  12. %Find_and_Get(what=proc printto print);
复制代码
Bye SAS.
若有缘,能重聚。

13
Tigflanker 发表于 2013-9-16 10:50:39
邓贵大 发表于 2013-9-15 23:04
add above to your code
Hi Deng,
Neither sysget("SAS_EXECFILEPATH") nor getoption("SYSIN") are available under my UNIX or PC SAS.
I try to understand your code and I believe it's also very useful to me.
Thank you again.
Bye SAS.
若有缘,能重聚。

14
Tigflanker 发表于 2013-9-16 14:09:14
邓贵大 发表于 2013-9-14 11:01
add above to your code
Thank you.
Problem have been solved by use sashelp.vextfl .
Bye SAS.
若有缘,能重聚。

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-1-1 06:15