楼主: zhiyong75
3663 2

[讨论]高手指点:如何存储SAS宏到永久数据库? [推广有奖]

  • 0关注
  • 1粉丝

硕士生

97%

还不是VIP/贵宾

-

威望
0
论坛币
2023 个
通用积分
0.1200
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
187 点
帖子
78
精华
0
在线时间
278 小时
注册时间
2006-9-5
最后登录
2017-8-20

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
高手指点:如何存储SAS宏到永久数据库?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:高手指点 SAS宏 数据库 讨论 高手 SAS 数据库 指点

回帖推荐

ermutuxia 发表于2楼  查看完整内容

你可以定义某一个逻辑库为一个文件夹,然后把程序放在那个文件夹里就可以

bakoll 发表于3楼  查看完整内容

SAS宏保存以便快速调用的三种解决方案 1.方式一:%include %include "full_path\sortds.txt"; inserts any code in the file called sortds.txt into your program at the location of the %include statement. Using this method, the macro must be recompiled every time a %INCLUDE is executed. Advantage: This approach was presented in SAS? at least 15+ years ago; it is an easy to use and straight forward ap ...

本帖被以下文库推荐

沙发
ermutuxia 发表于 2015-1-19 12:00:03 |只看作者 |坛友微信交流群
你可以定义某一个逻辑库为一个文件夹,然后把程序放在那个文件夹里就可以
已有 1 人评分论坛币 收起 理由
bakoll + 10 精彩帖子

总评分: 论坛币 + 10   查看全部评分

使用道具

藤椅
bakoll 发表于 2015-6-1 20:49:31 |只看作者 |坛友微信交流群
SAS宏保存以便快速调用的三种解决方案
1.方式一:%include
%include "full_path\sortds.txt"; inserts any code in the file called sortds.txt into your program
at the location of the %include statement. Using this method, the macro must be recompiled every
time a %INCLUDE is executed.
Advantage: This approach was presented in SAS? at least 15+ years ago; it is an easy to use and straight
forward approach.
Disadvantage: The macro definition is compiled every time the %INCLUDE is executed.

2.方式二:mautolocdisplay
Example:
filename autoM “C:\SESUGTEST\AUTOCALL_MACROS\”;
options mautolocdisplay mautosource sasautos = (autoM) ;

The macro is saved in the folder with fileref autoM as sortDS.sas but it is not a SAS? program, it is a macro. In our
program, we call the macro using %sortDS. Once the macro is called, we can see the source of macro code in the
log .
The advantage of using the autocall facility is that all user-defined macros are stored in a standard location and they
are not compiled until they are actually needed. The macro is stored uncompiled in an autocall library. It removes the
macro definition from the calling program itself. Macros defined in separate programs must be recompiled every time
that program is execute but the macro is compiled only once and then the compiled version can be reused during the
SAS? session without recompilation.


3.方式3:STORED COMPILED MACRO FACILITY

The most exciting method of saving macros is using the store compiled macro facility. The stored compiled macro
facility compiles and saves the macro source code in a permanent catalog. This compilation occurs one time, and can
store the source code permanently in a SASMACR catalog. Programs can always be retrieved, the macro will work,
but SAS? (macro processor) will not compile the macro again. This is the great feature of the stored compiled macro
facility.
具体实现:
options mstored sasmstore=mjstore;
libname mjstore “C:\SESUGTEST\Compiled_macro_library\”;

%macro sortDS (in=, out =, by=) / store source des="get sortDS macro“ ;  
* Macro for sorting data set &in. ;
proc sort data = &in.
            out = &out. ;
    by &by. ;
run ;  
%mend sortDS;

Advantages:   
1No repeated compiling of macro programs that are repeatedly used
2Possibility of displaying the entries in a catalog containing compiled macros saving macro compile time
3 There is no need to save and maintain the source for the macro definition in a different location
4 Keeping track of macros is easy
5 Storing more then one macro per file
6 Compile and Store is faster because there is a decrease in time for searching, %including, compiling and storing
in the WORK.SASMACR catalog.
Disadvantage:  
1 Cannot be moved directly to other operating systems.
2 Must be saved and recompiled under new OS at any new location.
将方式3的宏屏蔽的方法:
There is a way to hide code when executed so that it does not appear in the log. To avoid displaying code in the log,
store the code as a stored compiled macro. Because the macro is stored compiled, it cannot be seen in an editor.
More importantly, the options that write information about the code to the log can be turned off in the macro. The
following is a simple example:
屏蔽宏的程序实例
libname libref 'macro-storage-library-name';
options mstored sasmstore=libref;
%macro sortDS / store;
options nonotes nomlogic nomprint nosymbolgen nosource nosource2;
        ...more SAS? statements...
%mend;

By storing the code as a compiled macro, virtually no information is written to the log about the code. Only warnings
and errors will be written to the log

(转载)
stay hungry stay foolish

使用道具

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

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-25 09:48