Retrieving a Macro from SAS CATALOG

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Retrieving a Macro from SAS CATALOG

Hello all,

 

I am trying to retrieve code from a SAS catalog. I can view that there are 2 files of macro datatype in the sas catalog  I have used below code

data _null_;
infile macro;
input;
list;
run;

to retrieve a macro file. In the log I can see something like below, is there a way to view the actual SAS code? Please advise, any help is appreciated, Thanks!Capture.PNG

 

 


Accepted Solutions
Solution
‎09-19-2017 08:42 PM
Super User
Posts: 12,148

Re: Retrieving a Macro from SAS CATALOG

If the macro wasn't defined with the Source and Store options were used when the macro was compiled you are going to have lots of fun.

 

You might try to see if the options were used:

%copy <macro>/ library=< the library the macro is in> source;

 

Macro would NOT include the % and the LIbrary should be other than the default work if used.

If it works the default behavior will be to write the code of the macro to the log.

 

If it doesn't you might hope you can find the code that created the macro.

 

View solution in original post


All Replies
Super User
Posts: 21,572

Re: Retrieving a Macro from SAS CATALOG

Try %COPY.

 

%copy macro_name / SOURCE;

However, if the macro has not been compiled with the SOURCE option I'm not sure you'll get anything useful.

If the macro was compiled with the SECURE option you WILL NOT be able to reverse engineer the code. 

 

Any chance you can find the code used to build the macros?

 


sredd wrote:

Hello all,

 

I am trying to retrieve code from a SAS catalog. I can view that there are 2 files of macro datatype in the sas catalog  I have used below code

data _null_;
infile macro;
input;
list;
run;

to retrieve a macro file. In the log I can see something like below, is there a way to view the actual SAS code? Please advise, any help is appreciated, Thanks!Capture.PNG

 

 


 

Solution
‎09-19-2017 08:42 PM
Super User
Posts: 12,148

Re: Retrieving a Macro from SAS CATALOG

If the macro wasn't defined with the Source and Store options were used when the macro was compiled you are going to have lots of fun.

 

You might try to see if the options were used:

%copy <macro>/ library=< the library the macro is in> source;

 

Macro would NOT include the % and the LIbrary should be other than the default work if used.

If it works the default behavior will be to write the code of the macro to the log.

 

If it doesn't you might hope you can find the code that created the macro.

 

New Contributor
Posts: 2

Re: Retrieving a Macro from SAS CATALOG

Thank you! The Macro files are without % and are not saved by default in Work folder. So as you said this may not be defined with Source and Store options might have been used.

 

When I try to run below code

options sasmstore=lib.catalog;
%copy macro / source;

- it throws below errors, I am assuming it's because of the reason you specified. 

 'ERROR: Invalid logical name'

 'ERROR: An error occured during the execution of %COPY statement'

Super User
Posts: 12,148

Re: Retrieving a Macro from SAS CATALOG


sredd wrote:

Thank you! The Macro files are without % and are not saved by default in Work folder. So as you said this may not be defined with Source and Store options might have been used.

 

When I try to run below code

options sasmstore=lib.catalog;
%copy macro / source;

- it throws below errors, I am assuming it's because of the reason you specified. 

 'ERROR: Invalid logical name'

 'ERROR: An error occured during the execution of %COPY statement'


It may be that you requested the name of a macro that did not exist. Or possibly it is with the SASMSTORE option.

With errors it is best to post the code and the error message from the log into a forum code box. Sometimes the error message format will indicate where the error was detected but with the code the message is incomplete.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 194 views
  • 2 likes
  • 3 in conversation