貌似朋友们都看不懂我想要什么,所以我干脆自己写了个半成品贴上来,若是得不到帮助,无妨。
这个毛坯宏是一小时写好的,只是想传达个意思:
在第一部分将宏预读,第二部分伴随着程序,运行本宏。
本宏的预期目的是:将第二部分程序中依照'proc printto print'的线索抓取路径'output-file'
大致步骤为:
1. 将第二部分程序保存到文件 2. 将文件infile到数据库 3. 按照find找到目标 4. 进一步抓取需要的东西。
毛坯宏,很多细节没有考虑到。log窗口%put出结果:output-file
- 1.首先将这个宏预读。
- %Macro Find_and_Get(what=);
- *1.Save the current program into a temp file under E:\;
- dm 'file "E:\Find_and_Get_temp.txt" replace';
- *2.Read the program into dataset;
- data Find_and_Get_temp;
- infile "E:\Find_and_Get_temp.txt" delimiter=";";
- input code $500. @@;
- code=trim(code);
- run;
- *3.Find and Get it!;
- data _null;set Find_and_Get_temp;
- if find(code,"&what") and not find(code,"Find_and_Get");
- from=find(code,"'");to=find(code,"'",from+1);
- want=substr(code,from+1,to-from-1);
- call symputx('want',want);
- run;
- %put &want.;
- %Mend Find_and_Get;
复制代码- 2.以下是需要抓取的实例,其最后一行是调用的本宏。
- %Macro some_example;
- proc means data=grade maxdec=3;
- var Score ;
- class Status Year;
- types () status*year;
- title 'Final Exam Grades for Student Status and Year of Graduation';
- run;
- proc printto print='output-file'; *我希望运行本程序的同时,依照'proc printto print'的线索抓取到这个参数'output-file';
- run;
- %Mend;
- %Find_and_Get(what=proc printto print);
复制代码