SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 830|回复: 3
打印 上一主题 下一主题

请教高手:一个Macro的问题

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2004-11-10 23:43:38 | 只看该作者

请教高手:一个Macro的问题

I have a question about SAS Macro.
The question is:
After we defining a macro, we can store the macro defination in a external file or in a SAS catalog source entry, so another SAS program can call the macro with macro reference. I do know how to store a macro defination in a external file. Can you tell me how  to store a macro defination in a SAS catalog source entry?
Note: In this case, I want to  call macro by using %include statement, not by using autocall facility or by using stored compiled macro. (because calling macro by only %include statement does not need any system options as other methods do.)
For example, I have a macro defination like this:
%macro prtlast;

  %if &syslast ne _NULL_ %then %do;

      proc print data=&syslast(obs=5);

      title "Listing of &syslast data set";

      run;

  %end;

  %else

  %put No data set has been created yet.;

%mend;

I save it as C:\prtlast.sas and I can call this macro in another SAS program with code like:

%include 'C:\printlast.sas'/ source2;

%prtlast

So, again, my question is that how can I store the macro defination in SAS catalog source entry for beening called by another SAS program.



Thank you.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2004-11-11 13:47:54 | 只看该作者

a try

When you submit a macro definition, by default, the macro processor compiles and stores the macro in a SAS catalog in the WORK library. These macros, referred to as session compiled macros, exist only during the current SAS session. To save frequently used macros between sessions, you can use either the autocall macro facility or the
stored compiled macro facility.
The autocall macro facility stores the source for SAS macros in a collection of external files called an autocall library. The autocall facility is useful when you want to create a pool of easily maintained macros in a location that can be accessed by different applications and users. Autocall libraries can be concatenated together. The primary disadvantage of the autocall facility is that the first time that an autocall macro is called in a session, the macro processor compiles it. This compilation is overhead that
you can avoid by using the stored compiled macro facility.
The stored compiled macro facility stores compiled macros in a SAS catalog in a SAS data library that you specify. By using stored compiled macros, you might save macro compilation time in your production-level jobs. However, because these stored macros are compiled, you must save and maintain the source for the macro definitions in a different location.The autocall facility and the stored compiled macro facility each offer advantages.Some of the factors that determine how you choose to save a macro definition are how often you use a macro, how often you change it, how many users need to execute it, and how many compiled macro statements it has. If you are developing new programs, consider creating macros and compiling them during your current session. If you are running production-level jobs using name-style macros, consider using stored compiled macros. If you are allowing a group of users to share macros, consider using the autocall facility.

You can see details in SAS® 9.1 Macro Language chapter9.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2004-11-11 22:56:05 | 只看该作者

I don't think online doc cover my topic

I already reviewed online doc and that topic do not cover what I want.
There 4 ways to call Macro:
1- session compiled macro
2- %include statement (External file or SOURCE catalog entry)
3- Autocall facility (External file or SOURCE catalog entry)
4- Stored compiled Macro
My question is about %include statement(Source catalog entry)
By the way, when I use autocall, I still have problem, here is my code:

%macro prtlast;
  %if &syslast ne _NULL_ %then %do;
      proc print data=&syslast(obs=5);
      title "Listing of &syslast data set";
      run;
  %end;
  %else
  %put No data set has been created yet.;
%mend;

I save it as C:\prtlast.sas and I try to call this macro in another SAS program with code like:

options mautosource sasautos='C:\';
%include prtlast/ source2;
data course;
      infile datalines dsd dlm=',';
      length teacher $20;
      input course_id teacher $ tuition;
      datalines;
      1,"James liu",1000
      2,"Gary Guo",2341
      3,"Someone else",231
      4,"Vivian Pan",1000
      5,"feng gao",1000
      ;
run;
%prtlast

I got

WARNING: Physical file does not exist, C:\Documents and Settings\gary_guo\prtlast.sas.

ERROR: Cannot open %INCLUDE file PRINTLAST.

I do not know why autocall facility doesn't work. I checked the system option, the option of SASAUTOS is set to "C:\".
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2004-12-18 10:21:34 | 只看该作者

Have a try

Try as followed,maybe it'll work:
1.
%include "C:\prtlast.sas"/ source2;

2.
OPTIONS MAUTOSOURCE SASAUTOS=('C:\',SASAUTOS);
回复 支持 反对

使用道具 举报

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

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2025-6-8 21:17 , Processed in 0.071295 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表