BookmarkSubscribeRSS Feed
Obsidian | Level 7

Dear expert.

I want to retrieve the source code of a compiled macro, and this macro is compiled without source & secure option specified.

I tried to retrieve the code using:


options mstored sasmstore=mylib;
libname mylib "mypath";

  filename maccat catalog '';
  data _null_;
    infile maccat;

and the output in log is:

CHAR  ....E.......%AHGwinorunix=WIN.... 33
ZONE  000040001000244476667766735440000
NUMR  500050001000518779EF25E98D79E0000
CHAR  &............... 16
ZONE  2000000000000000
NUMR  6000300030000000
CHAR  &............... 16
ZONE  2000000000000000
NUMR  6000400050000000
CHAR  ....E...     %AHGpipe(.dir %AHGaddslash(&dir) .b. );     %AHGpm(rcpipe);.... 81
ZONE  000040002222224447676206672244466676676226672127672160223222222444762767676230000
NUMR  30005000000005187090581492051871443C1388649297E313082209B0000051870D82309059B0000

This format is not readable.


Could anyone give me some hints on how to retrieve the source code from compiled macro?

Or try to format the above code into readable SAS program?


Amethyst | Level 16

Please try the mfile option with filename and mprint. The syntax is as follows, when you run it, the file will be created and in this the source code of the compiled macro will be saved.

filename mprint 'c:\';
options mprint mfile;

%macro test;

your macro code ;



Obsidian | Level 7


Calcite | Level 5

There is no way to retrieve the original source code from a stored compiled macro. You must always save the original code in another file so that you can modify it later.

Regards: reviews

Obsidian | Level 7




I've tried your suggested syntax however mprint log couldn't printed in the file.


Can you please provide exact way to get mprint print into the file.





Diamond | Level 26 RW9
Diamond | Level 26

Please note this topic is 3 years old.  Please open a new post and provide as much details and examples as possible.


If your compiled macro was not created with the SOURCE option then unfortunately there is no way to retrieve it:



Obsidian | Level 7
That's really sad
Diamond | Level 26 RW9
Diamond | Level 26

No, that is a really good examplpe of why to avoid proprietary file formats.  We had the same thing, years of vendors sending us code hidden in black box compiled catalogs.  When 64bit SAS came along these became inaccessible, hence any use of them now has to be re-programmed from the start.  So take this as a learning exercise, always use plain text easily transportable file formats that are not tied to any software.  We specifically put in all our contracts this now and don't work with those companies who hide things in compiled catalogs or other methods.

Opal | Level 21


But you would agree that this isn't really a SAS issue as SAS allows to store the source code with the compiled macro or alternatively also provides the SAS Autocall facility where you don't need to pre-compile the macros at all.

Diamond | Level 26 RW9
Diamond | Level 26

Well, yes, but also no.  They do offer methodologies to utilise this in a process and retain the open mentality.  However, for the most times I have seen catalogs used, it is to hide code.  This may just be a thing in my industry, but its only in recent years that vendors have been more accepting of not hiding their code.  Even now, some of what we are sent is hidden in catalogs, and its makes it next to impossible for us to decipher what is going on.  With the use of CDISC standards going forward, and the need to provide methodologies, this will have to change.


So yes, its not SAS directly, but those compaines who use the tech in this manner.  But then you get in to the the cyclic argument of which is the problem, the gun, or the people buying them?


Moving on from there, functions are even worse.  The code is hidden and the calls to them maskerade as normal functions, not even a % to indicate difference.


As a general policy I never use SAS compilation options such as macros as I've never found enough advantages to outweigh the disadvantages - like you have found.

SAS Employee


If you stored macro in this folder:

libname mylib '/home/folder/StoredMacros/';

You can recall all macro saved


options mstored sasmstore=mylib;

With this proceduce you can print a list of macros from catalog:


proc catalog CATALOG=mylib.sasmacr ;

Another option to get a list of macros using a filter on the dictionary alfter calling stored macro(all variable in the DICTIONARY tables is always in uppercase😞

proc sql;
select *
from dictionary.catalogs
where objtype='MACRO' and libname='MYLIB';

You can use "%COPY Statement" to print macro on log or file.



filename printmcr '/';
%copy mymacro / source;
%copy mymacro /OUTFILE=printmcr source;




Super User

Another necro thread.


You can only recover the source if the macro was not compiled with the SECURE option.

Calcite | Level 5

Retrieving the source code of a compiled macro, such as a CapCut Reels template, is typically not possible. When code is compiled, it's transformed into machine-readable instructions, making it difficult to revert to the original source code. To access the source code, you would need the uncompiled version or the developer's files, which may not be publicly available for templates like CapCut Reels due to copyright and proprietary reasons.



Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.


Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 14 replies
  • 10 in conversation