Discussion:
List Macro path without executing macro
(too old to reply)
Patrick
2008-07-17 23:42:34 UTC
Permalink
Hi all

I have a piece of code with a macro call - but I don't know where the
macro comes from.

How can I get the location of the macro - it could be in an autocall
library (sasautos) or in a catalog (sasmstore).

I've seen the MAUTOLOCDISPLAY option - but how to use it without
executing the macro?

Cheers

Patrick
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-18 14:08:26 UTC
Permalink
From: Patrick
I have a piece of code with a macro call - but I don't know where the
macro comes from.
How can I get the location of the macro - it could be in an autocall
library (sasautos) or in a catalog (sasmstore).
I've seen the MAUTOLOCDISPLAY option - but how to use it without
executing the macro?
when you solve this problem,
you graduate from being a user to being a programmer.

0. find your autoexec which may redefine any of the options associated
w/macro use

1. list the SASautos fileref

filename SASautos list;

2. list the SASautos option:

Proc Options define value option = SASautos;

%Put SASautos:%sysfunc(getoption(SASautos));

3. now you know the folders that contain SAS-supplied macros
go to !sasroot

C:\Program Files\SAS\SAS 9.1

and look under each product you have licensed for the folder sasmacro:

C:\Program Files\SAS\SAS 9.1\access\sasmacro
C:\Program Files\SAS\SAS 9.1\assist\sasmacro

C:\Program Files\SAS\SAS 9.1\...\sasmacro

C:\Program Files\SAS\SAS 9.1\stat\sasmacro


4. catalogs

4.1 find the libref containing the catalog:

%Put SASmStore:%sysfunc(getoption(sasmstore));

4.2 if libref in sasmstore meaning macros are available in a catalog,
list the libref folder:

filename %sysfunc(getoption(sasmstore)) list;

which does not tell you where the file containing the macro definition
is located
it tells, as you asked, whether the macro is in a catalog.
From which folder it was compiled and stored is still a Q.

5. read the paper:

http://www.sascommunity.org/wiki/SASautos_Companion_Reusing_Macros


Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Patrick
2008-07-19 07:16:15 UTC
Permalink
Hi Ron

I appreciate your answer and thanks for the link.
I hope you know that your first remark was rather offensive. Quite
unnecessary!

What you describe as solution is exactly what I tried to avoid: To
manually do what the SAS macro compiler does in a way when I call a
macro.

My thought was: If SAS is able to find a macro when I call it, isn’t
there a way to let SAS do the job for me without executing the macro
(may be by only compiling it) and then retrieve the information where
SAS found the macro.

By the way: If you speak any language different from your native one
then try for a change to formulate a precise question in this other
language – and you will see how difficult that is.

Regards

Patrick
data _null_,
2008-07-19 11:34:55 UTC
Permalink
If you know the names of the macros you want to "MAUTOLOCATE" then you
could do something like this. I does compile each one but the call is
in error so they don't run. Some may run I would guess if they use
parmbuf.

filename FT17F001 temp lrecl=512;
options nomprint MAUTOLOCDISPLAY;

proc printto log=FT17F001;
run;
data _null_;
input macro:$32.;
call execute(cats('%nrstr(%',macro,'(_=_,,));'));
cards;
left
angle
compstor
ds2csf
adxgen
;;;;
run;
Proc printto;
run;
data MAUTOLOCDISPLAY;
infile FT17F001 truncover;
input @'MAUTOLOCDISPLAY' Macro:$34. @'autocall file' path $256.;
macro = compress(macro,'):(');
if not missing(macro) then output;
*list;
run;
proc print;
run;
Post by Patrick
Hi all
I have a piece of code with a macro call - but I don't know where the
macro comes from.
How can I get the location of the macro - it could be in an autocall
library (sasautos) or in a catalog (sasmstore).
I've seen the MAUTOLOCDISPLAY option - but how to use it without
executing the macro?
Cheers
Patrick
Ian Whitlock
2008-07-19 21:27:04 UTC
Permalink
Summary: %BQUOTE does not execute generated SAS code
#iw-value=1

Data_null_ wrote in part
Post by data _null_,
If you know the names of the macros you want to "MAUTOLOCATE" then
you could do something like this. I does compile each one but the
call is in error so they don't run. Some may run I would guess if
they use parmbuf.
I like to use %BQUOTE to check generated SAS code without executing
it. Using two of Datat_null_'s examples

options nomprint MAUTOLOCDISPLAY;
%let m = %bquote(%angle %left) ;

In the first case, quoted SAS code is generated as could be shown with

%PUT &m ;

and in the second case, the code is just macro instructions, but they
are executed as with the option MLOGIC.

If you must stop compilation and can suffer error messages then I
would simplify Data_null_'s forced error with

%let m = %bquote(%angle($=)) %bquote(%left($=)) ;

NOTE: At first I couldn't make his PROC PRINTTO work. It turns out
that the reason was that I was running in batch. His code must be run
interactively, otherwise the error causes the subsequent DATA step to
not work.

In general I suspect the only way to avoid macro execution of a macro
without creating an error is to not call it, i.e. use some form of
searching in relevant directories. Since the macro in question is
presumably in an autocall library, you know the filename,
<macro_name>.SAS On the other hand, don't overlook the autoexec since
it could compile a macro without messages.

Ian Whitlock
data _null_,
2008-07-19 21:56:59 UTC
Permalink
Post by Ian Whitlock
NOTE: At first I couldn't make his PROC PRINTTO work. It turns out
that the reason was that I was running in batch. His code must be run
interactively, otherwise the error causes the subsequent DATA step to
not work.
I did all my testing from display manager, that detail was overlooked.
The option NOSYNTAXCHECK will solve that problem when run in batch
SAS.
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-21 15:01:46 UTC
Permalink
From: Patrick
Hi Ron
I appreciate your answer and thanks for the link.
I hope you know that your first remark was rather offensive. Quite
unnecessary!
No offense was intended.
Friday was a full moon;
I have a broken right thumb
and am still getting good at typing spaces w/my left thumb;
I am a geezer.
What you describe as solution is exactly what I tried to avoid: To
manually do what the SAS macro compiler does in a way when I call a
macro.
My thought was: If SAS is able to find a macro when I call it, isn't
there a way to let SAS do the job for me without executing the macro
(may be by only compiling it) and then retrieve the information where
SAS found the macro.
I don't think so.
Compile and store may be two distinct conceptual operations
but they are a unit operation when SAS does it.

If I were doing this task,
I would be using my utility ListMcat

http://www.sascommunity.org/wiki/ListMcat.sas

to provide a list of the macros
used by previously run jobs.

You could insert this at end of every program
with the termstmt command

http://www.sascommunity.org/wiki/Option_TermStmt

this will highlight what kind of discipline there is in your company
as to documenting macros with the description option.

my recommendation is:

%MACRO DoThis
(data =
,...
)/ des = 'site: description of this macro'
;

No one will ever getting around to doing this
but I would like to see all SAS-Institute supplied macros with
des = '<product-name> description'

where produce-name is the name of the folder containing the macro

I think you want to do a freeze-frame:
"Computer!
Stop right here!
Where did you find that macro?"

My opinion is that your solution will be a retrospective.

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Jack Hamilton
2008-07-21 15:12:07 UTC
Permalink
On Mon, 21 Jul 2008 11:01:46 -0400, "Fehd, Ronald J. (CDC/CCHIS/NCPHI)"
Post by Fehd, Ronald J. (CDC/CCHIS/NCPHI)
No one will ever getting around to doing this
but I would like to see all SAS-Institute supplied macros with
des = '<product-name> description'
where produce-name is the name of the folder containing the macro
Lettuce be more careful about proofreading!



--
Jack Hamilton
Sacramento, California
***@alumni.stanford.org <== Use this, not ***@stanfordalumni.org
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-21 15:19:55 UTC
Permalink
From: Ian Whitlock
In general I suspect the only way to avoid macro execution of a macro
without creating an error is to not call it, i.e. use some form of
searching in relevant directories. Since the macro in question is
presumably in an autocall library, you know the filename,
<macro_name>.SAS On the other hand, don't overlook the autoexec since
it could compile a macro without messages.
one of the interesting features of the autocall command
is that it searches for a filename matching the macro name
and compiles-and-stores all the macros in the file.

try this:

%Include 'C:\Program Files\SAS\SAS
9.1\core\sasmacro\annomac.sas'\source2;

PROC Catalog catalog = Work.SASmacr;
contents;
quit;

note: no description for any of the 40 macros in the file!

I had it on my todo list for a year or so after I published my SASautos
paper
to develop a program that would

* get SASautos value
%Let SASautos = %sysget(SASautos);

-SET SASAUTOS (
"!sasroot\core\sasmacro"
...
"!sasext0\stat\sasmacro"
)

* replace/tranwrd sasroot and sasext0 in each directory-specification

-SET sasext0 "C:\Program Files\SAS\SAS 9.1"

-SET sasroot "C:\Program Files\SAS\SAS 9.1"

* for each folder
* get directory
* for each file %include
* create data set of all macros compiled from each file.

tada: list of SAS-supplied macros and file where they are located

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-21 15:50:07 UTC
Permalink
From: Jack Hamilton
Post by Fehd, Ronald J. (CDC/CCHIS/NCPHI)
No one will ever getting around to doing this
but I would like to see all SAS-Institute supplied macros with
des = '<product-name> description'
where produce-name is the name of the folder containing the macro
Lettuce be more careful about proofreading!
ROFLMAO
well, my week is off to a laughing start!

... and that was the index finger of The Good Hand!

Ron Fehd geezer, gimp, ... whichever
the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-21 19:56:32 UTC
Permalink
I have a program IncludeFileName working that
* includes one file
* copies the Work.SASmacro.catalog to dataset
* adds variables with parameters

http://www.sascommunity.org/wiki/Listing_Macros_in_SASautos

what's needed: utility to read list of files in a folder.

Ron Fehd the SASautos
and macro maven CDC Atlanta GA USA RJF2 at cdc dot gov
Patrick
2008-07-22 01:10:51 UTC
Permalink
Thanks to all of you. This was helpful.
I know now that I didn't overlook something simple and obvious.
I think I will try to scan through the components involved cfg (isn't
there an -initsyst), autoexec(s) and so on.
A nice task for the next time "on the bench".
Cheers
Patrick
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-22 14:42:17 UTC
Permalink
From: Patrick
Thanks to all of you. This was helpful.
You are welcome, SAS-L is just one of the mini assets in your SAS
network.
I know now that I didn't overlook something simple and obvious.
always a relief to have everything checked off
I think I will try to scan through the components involved cfg
you have at least two SASv9.cfg:

...\SASv9.cfg the secondary config which calls the primary
config
...\nls\en\SASv9.cfg your primary config: The Big One

check your project folder, there may be a ternary config there
(isn't there an -initsyst), autoexec(s) and so on.
PROC Options define value option = initstmt;
PROC Options define value option = termstmt;
run;

for testing your autoexec and seeing the complete list of config files
used
see AutoExecTest in:

http://tinyurl.com/6zlqoh

http://www.sascommunity.org/wiki/Batch_processing_under_Windows
A nice task for the next time "on the bench".
... where we all learn our memorable ("AhhhHa!") lessons

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov

Maximum fun! -- Linus Torvalds, creator of Linux

If you want creative workers,
give them enough time to play.
-- John Cleese, comic actor (1939- )
Fehd, Ronald J. (CDC/CCHIS/NCPHI)
2008-07-22 18:39:53 UTC
Permalink
I have extracted the list of v9.1.3 macros and posted it to this page:

http://www.sascommunity.org/wiki/Listing_Macros_in_SASautos

Ron

Loading...