BookmarkSubscribeRSS Feed
Obsidian | Level 7



I need to generate the code in executable syntactically correct format.


For eg,  I have one sample small custom made application which has multiple sas file and macros, which are being executed based on logic written. Now what I want is, for any execution case , this SAS application not only generate the result in form of dataset or any other desired output but also give me a executable SAS code.

Purpose is to ensure that resultant final limited SAS code can be execute on any other machine by providing the same input from where it has been generated.


Currently I know that SAS can generate the code lines whatever has been executed but that is not executable sas code. It just show what are all code line have been executed as per my custom application logic.


Is it achievable or I am over expecting it ?



Tushar Jain

Diamond | Level 26 RW9
Diamond | Level 26

SAS is an interpreted language, the compiler compiles the code on the fly at run time.  To run SAS code on other machines they also need a fully licensed SAS install.  You can however execute scripts remotely on a server, i.e. send a request to a server which has SAS installed, to run some given code, and then get results sent back.  But you wouldn't get a dll or exe of your code.

Super User Tom
Super User

You cannot compile SAS code.

Just give the whole program to whoever needs to use it and explain to them how to provide the inputs it needs.

More details will depend on how you are running the program (just base SAS, using stored process servers, Enterprise Guide, SAS/Studio, etc. etc. etc.).


If you are making a general purpose program than make sure to validate user inputs before proceeding to doing the actual processing steps. For example if one input is the name of an input dataset then check if the dataset exists before trying to use it. That way you can give the user a clear error message instead of forcing them to interpret the error that SAS will generate when the dataset is not found.


SAS procedures are already precompiled modules.  There is no way that the source code can be saved as an executable.


DATA steps can be compiled, and the compiled code saved.  However, you would need to take the source code and modify it slightly to do that.


Should I assume you know about the MFILE / MPRINT options that allow you to save macro-generated source code in a file? 

Garnet | Level 18

I'm not sure if it worths the effort, but depending on complexity of your code you always can create the code to run - programatiaclly 

into a file then %INCLUDE it to run it.


Here is a skeleton of what I mean:

filename my_prog '...path and';

%macro generate(...argumants...);
     data _NULL_;
         file my_prog;
            .... code to generate the program...
            .... according to arguments ......
            .... written as text into my_prog file ...
     %include my_prog;
%mend generate;

save file my_prog - that is the generated code.

Pyrite | Level 9

You can save the code using SAS Studio then copy the .SAS file to removable media.


You can copy the code and paste it into a word processor, and save it as a DOC, DOCX, or TXT file.

Move it to another machine.

Super User

I don't think your question is clear. You need to clarify in detail what you want to happen and what you mean by executable code. 

Right now we're making assumptions which is problematic.

Obsidian | Level 7

Thanks all for the responses.


I want to restate my question as,

I have SAS application spread across multiple sas code file and macros. Every time I run a code, it will go through limited set of code lines due to different conditional statements. Code accepts few input as sysparm and by reading the many parameter files during execution along with input sas dataset to be processed. And produce some resultant report and output dataset.

Now , what I want is, every time I execute the sas application, system should save only the executed code part as SAS file. So that, this limited sas code can be executed 'as is' on different sas machine by just proving the sysparm, parameter file and input datasets.


for eg,

In sas application I have 'if' and 'else' statements, and during execution,  sas code chooses only 'if' part statements. Then I wants that generated sas code must have only 'if' line statements and which can be executed 'as is' on another machine.


Hope I have stated it corretly. or please suggest if I need to clarify anything else.




Ammonite | Level 13

I think what you want to do can only be achieved by Shmuels's suggestion above which would mean refactoring all your existing code.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 8 replies
  • 8 in conversation