We're calling the macro as below which will help identify the environment (dev, test, prod) and the job name. Can someone help me where can I find the macro definition for the same? I searched in few folders for this macro but I couldn't locate it. I checked the log of this macro but I couldn't identify the location of the macro %env_jobname.
options symbolgen mlogic mprint; %env_jobname(var_name=path);
Can you start a new session, then run that code and post the log? If %ENV_JOBNAME is an autocall macro, mlogic should write a note to the log when it is compiled. If the macro isn't an autocall macro, than you might try turning on system option mcompilenote=ALL. That will write a note to the log when macro is compiled, so you could run the code (in a fresh SAS session), and then search the log.
Below shows the log I get from testing it out with %lowcase, which is an autocall macro provided by SAS:
1 options mlogic mcompilenote=all; 2 %put %lowcase(FOO); MLOGIC: Beginning compilation of LOWCASE using the autocall file C:\Program Files\SASHome\SASFoundation\9.4\core\sasmacro\lowcase.sas. NOTE: The macro LOWCASE completed compilation without errors. 29 instructions 504 bytes. MLOGIC(LOWCASE): Beginning execution. MLOGIC(LOWCASE): This macro was compiled from the autocall file C:\Program Files\SASHome\SASFoundation\9.4\core\sasmacro\lowcase.sas MLOGIC(LOWCASE): Parameter STRING has value FOO MLOGIC(LOWCASE): Ending execution. foo
You would want to set these options as early as possible in your SAS session, as it could be that that macro is created by running an autoexec file.
Yes, MCOMPILENOTE=ALL works for autocall macros. The documentation is:
That option will tell you *when* a macro is compiled, but it doesn't tell you the location of the file.
MLOGIC tells you the location of an autocall macro when it is compiled (and each time it is executed).
If you couldn't use MLOGIC for some reason, you could use MAUTOLOCDISPLAY:
12 options nomlogic mautolocdisplay; 13 %put %lowcase(FOO); MAUTOLOCDISPLAY(LOWCASE): This macro was compiled from the autocall file C:\Program Files\SASHome\SASFoundation\9.4\core\sasmacro\lowcase.sas foo
That said, if you turn on MLOGIC and run the macro call and it does NOT show the location, that means the macro is not an autocall macro.
In below example, I turn on MLOGIC. When I call %lowcase() the location is printed, because it's an autocall macro. When I call %foo the location is not printed, because it's not an autocall macro.
60 options mlogic; 61 62 %lowcase() MLOGIC(LOWCASE): Beginning execution. MLOGIC(LOWCASE): This macro was compiled from the autocall file C:\Program Files\SASHome\SASFoundation\9.4\core\sasmacro\lowcase.sas MLOGIC(LOWCASE): Parameter STRING has value MLOGIC(LOWCASE): Ending execution. 63 64 %foo() MLOGIC(FOO): Beginning execution. MLOGIC(FOO): %PUT hi hi MLOGIC(FOO): Ending execution
One more place I would look would be some of "autoexec.sas" files, maybe one of the workspace server? Macro definition could be hidden there.
For list of autocall directories you can run:
proc options option=SET; run;
Maybe it will show you some locations you missed.
If it is not from autoexec or autocall, it may be one stored in a catalog.
If that is the case, it will be rather bad situation because even you try read the catalog content:
%macro MyMacro(); %if &x.=1 %then %do; options mprint mlogic symbolgen; data abc; x = 1; y = 2; z = x + y; put "Can you see me??:-)"; put _all_; run; %end; %mend MyMacro; filename os catalog 'work.sasmacr.MyMacro.macro'; data _null_; infile os; input; put _INFILE_; run;
Output in the log would be rather messy:
1 %macro MyMacro(); 2 %if &x.=1 %then 3 %do; 4 options mprint mlogic symbolgen; 5 data abc; 6 x = 1; 7 y = 2; 8 z = x + y; 9 put "Can you see me??:-)"; 10 put _all_; 11 run; 12 %end; 13 %mend MyMacro; 14 15 filename os catalog 'work.sasmacr.MyMacro.macro'; 16 data _null_; 17 infile os; 18 input; 19 put _INFILE_; 20 run; NOTE: The infile OS is: Catalog Name=WORK.SASMACR.MYMACRO.MACRO, Catalog Page Size=4096, Number of Catalog Pages=246, Created=Sun, May 28, 2023 09:06:15 PM, Last Modified=Sun, May 28, 2023 09:06:15 PM, Filename=********************\sasmacr.sas7bcat, Release Created=9.0401M8, Host Created=X64_10PRO, Owner Name=YABWONL5P\bart, File Size= 981KB, File Size (bytes)=1004544 MYMACRO vZ 9.4 @ ¤ 4 0 & &x.=1 & & — options mprint mlogic symbolgen; data abc; x = 1; y = 2; z = x + y; put "Can you see me??:-)"; put _all_; run; & & & # ( 8 H ì ü 0 NOTE: 12 records were read from the infile OS. The minimum record length was 4. The maximum record length was 163. NOTE: DATA statement used (Total process time): real time 0.43 seconds user cpu time 0.04 seconds system cpu time 0.21 seconds memory 315.40k OS Memory 24060.00k
You might want to try this old macro (created before those new fangled system options existed).
It will get the list of currently compiled macros and try to find if there is a file with that name in the directories listed in the SASAUTOS system option.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.