某些时候我们可能需要隐藏SAS的源代码,这时我们可以把需要隐藏的代码放到宏里,并对宏进行加密。具体方法根据网上的一些文章介绍,进行如下测试:
第一步:生成加密的宏
/*加密宏*/
LIBNAME test ‘c:\test’;
OPTIONS MSTORED SASMSTORE=test;
%macro foobar1(arg) /store des=”This macro if for test”
/*source*/;
%put arg = &arg;
%mend;
%macro foobar2(arg) /store des=”This macro if for test”
/*source*/;
%put arg = &arg;
%mend;
生成的两个宏保存在c:\test目录下的sasmacr.sas7bcat文件中,经测试,可以修改或者增加宏。
第二步:调用已经加密的宏
LIBNAME test ‘c:\test’;
OPTIONS MSTORED SASMSTORE=test;
/*如果生成宏的时候有source选项,可以用以下命令打印出宏的源代码*/
/*%copy foobar1/source;*/
%foobar1(“this is test1”);
%foobar2(“this is test2”);
日志如下:
加密的宏运行没有问题。这里需要注意,如果需要在加密的宏中保存源代码,可以加上source选项,但是这个选项也使得加密没有意义了,因为可以使用%copy直接把源代码打印出来。
%copy foobar1/source;
示例中我没有使用source选项,所以%copy命令无法正常使用。
以上就完成了加密和调用的测试,但是这还没有完,这样的加密一样是没用的,因为宏选项中MPRINT可以让宏运行前先打印宏的代码,请看下面的测试结果。
代码:
LIBNAME test ‘c:\test’;
OPTIONS MSTORED SASMSTORE=test;
%macro foobar1 /store des=”This macro if for print”
/*source*/;
proc print data=sashelp.class;
where sex=”F”;
run;
%mend;
以上代码修改了之前定义的宏foobar1 。
调用代码如下,加入了OPTIONS MPRINT;语句。
LIBNAME test ‘c:\test’;
OPTIONS MSTORED SASMSTORE=test;
OPTIONS MPRINT;
%foobar1;
结果如下:
可见,加密同样无效,这时我们需要在宏内设定选项覆盖全局选项MPRINT(每个宏都需要设置),具体修改如下:
LIBNAME test ‘c:\test’;
OPTIONS MSTORED SASMSTORE=test;
%macro foobar1 /store des=”This macro if for print”
/*source*/;
options nomprint nosource;
proc print data=sashelp.class;
where sex=”F”;
run;
%mend;
这样宏的加密就完成了,当然如果您发现还有其他能访问宏源代码的方式,欢迎指正。
本文为一起大数据首发,转载请注明:“一起大数据 ”及 本文链接,谢谢支持。