楼主: 凡尘梦1990
17804 17

sas宏,如何将自己写的宏程序永久储存和调用 [推广有奖]

11
凡尘梦1990 学生认证  发表于 2016-1-20 21:08:47
chinatyq 发表于 2016-1-19 20:26
你可以在SAS安装目录下创建一个SAS程序,名为:autoexec.sas,写上%inc "D:\你的程序名.sas
嗯嗯 多谢 我已经会弄了。

12
幽焉 发表于 2016-4-28 12:13:14
请问可以详细的展示一下你的过程么?我也不太明白,谢谢了

13
rendajingguan01 发表于 2016-4-28 13:09:46
我直接把书贴上来吧,看来你需要看看

Compiling an Externally Stored Macro Definition with the %INCLUDE Statement
%include 'c:\sasfiles\prtlast.sas' / source2;
proc sort data=sasuser.courses out=bydays;
by days;
run;
%prtlast
Listing the Contents of a Catalog
proc catalog cat=work.sasmacr;
contents;
title "Default Storage of SAS Macros";
quit;
Using the Catalog Access Method
filename prtlast catalog 'sasuser.mymacs.prtlast.source';
%include prtlast;
proc sort data=sasuser.courses out=bydays;
by days;
run;
%prtlast
Accessing an Autocall Macro
options mautosource sasautos=('c:\mysasfiles',sasautos);
%prtlast
Creating a Stored Compiled Macro
libname macrolib 'c:\storedlib';
options mstored sasmstore=macrolib;
%macro words(text,root=w,delim=%str( ))/store;
%local i word;
%let i=1;
%let word=%scan(&text,&i,&delim);
%do %while (&word ne );
%global &root&i;
%let &root&i=&word;
%let i=%eval(&i+1);
%let word=%scan(&text,&i,&delim);
440 Chapter 12 • Storing Macro Programs
%end;
%global &root.num;
%let &root.num=%eval(&i-1);
%mend words;
Points to Remember
•You can make macros available to your programs in four ways: as session-compiled macros, with a %INCLUDE statement, through the autocall facility, or as stored compiled macros.
•If you use the autocall facility, you must specify the MAUTOSOURCE and SASAUTOS= system options.
•If you use the stored compiled macro facility, you must specify the MSTORED and SASMSTORE= system options.
•The point at which macro compilation occurs depends on which method you use to access the macro.
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
凡尘梦1990 + 3 + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 3  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

14
凡尘梦1990 学生认证  发表于 2016-5-8 21:44:21
幽焉 发表于 2016-4-28 12:13
请问可以详细的展示一下你的过程么?我也不太明白,谢谢了
楼下的就是解答哈 我就是照着他的方法弄的

15
幽焉 发表于 2016-5-8 22:51:22
谢谢,非常感谢!

16
肉嘟嘟316 发表于 2016-11-17 13:34:43
弱弱的问一句   %INC 后面的/SOURCE2 是什么意思呀??

17
coelicolor 发表于 2017-6-15 04:27:04

检索到,学习一下,

18
行路者01 发表于 2017-9-12 22:55:36
其实宏存储于调用是一门技巧活。
首先,存储时,用下面语句定义好宏存储的逻辑库及位置位置;

libname fl 'd:\';
options mstored sasmstore=fl;
其次,将需要重复使用的宏编译存储好:

%macro test/store;
...your sas sentence...
%mend test;
最后,如果需要调用时,需要重复最开始定义的宏位置及名称
libname fl 'd:\';
options mstored sasmstore=fl;
这样你就可以使用你的宏了,是不是很炫酷啊。。。
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
凡尘梦1990 + 3 + 1 + 1 + 1 精彩帖子

总评分: 论坛币 + 3  学术水平 + 1  热心指数 + 1  信用等级 + 1   查看全部评分

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

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