7月 10, 2011
使用%nowpath宏获取当前SAS路径
前几天学习了一个叫mypath的宏,其实现了将当前sas程序的路径定义为一个宏变量、以方便后续调用路径的功能。查了下相关资料,在《Generating Program-Stamped Output in an Interactive SAS Session》中,也有个叫fullpath的宏,是提取当前路径为宏变量后进行应用。
个人觉得这2个实现路径提取功能的宏及其中的编程技巧挺有用的,拿出来分享一下。
1.%nowpath
1.1
将%mypath和%fullpath作了小小改动、整合成了下面的宏%nowpath
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | %macro nowpath; %global fullpath nowpath; /*定义为global,为后续调用准备*/ proc sql noprint; select xpath into : fullpath /*选取全路径*/ from dictionary.extfiles /*dictionary.extfiles包含SAS路径信息*/ where substr(fileref,4) eq ( select max(substr(fileref,4)) /*max()保证选取最新(当前)路劲*/ from dictionary.extfiles where substr(fileref,1,1) eq "#" and index(xpath,".sas") gt 0 ); quit; /*选取当前路径*/ %let nowpath=%substr(&fullpath,1,%eval(%length(&fullpath)-%length(%scan(&fullpath,-1,\)))); %put The Full Path is: &fullpath; %put The Now Path is: &nowpath; %mend nowpath; |