BookmarkSubscribeRSS Feed
ChaseLiu
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 'mylib.sasmacr.secure.macro';
  data _null_;
    infile maccat;
    input;
    list;
  run;

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)..sas .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?

 

14 REPLIES 14
Jagadishkatam
Amethyst | Level 16

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

filename mprint 'c:\mysasfile.sas';
options mprint mfile;
run;

%macro test;

your macro code ;

%mend;

%test;

Thanks,
Jag
ChaseLiu
Obsidian | Level 7

Thanks 

fomapi5870
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

jaiganesh
Obsidian | Level 7

Hello,

 

 

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.

 

 

Regards,

Jai  

RW9
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.

SASKiwi
PROC Star

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

 

http://support.sas.com/kb/22/352.html

 

 

ChaseLiu
Obsidian | Level 7
That's really sad
RW9
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.

Patrick
Opal | Level 21

@RW9

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.

RW9
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.

SASKiwi
PROC Star

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.

Luisfco88
SAS Employee

Hi,

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 ;
Contents;
run;
quit;

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';
quit;

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

 

 

filename printmcr '/mysasfile_mymacro.sas';
%copy mymacro / source;
%copy mymacro /OUTFILE=printmcr source;

 

 

Regards,

ballardw
Super User

Another necro thread.

 

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

xememo
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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 9898 views
  • 8 likes
  • 10 in conversation