DATA Step, Macro, Functions and more

Generate executable SAS code

Reply
Occasional Contributor
Posts: 9

Generate executable SAS code

Folks,

 

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 ?

 

Thanks,

Tushar Jain

Super User
Super User
Posts: 7,401

Re: Generate executable SAS code

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
Super User
Posts: 6,499

Re: Generate executable SAS code

[ Edited ]

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.

Super User
Posts: 5,081

Re: Generate executable SAS code

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? 

Trusted Advisor
Posts: 1,372

Re: Generate executable SAS code

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 name.sas';

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

save file my_prog - that is the generated code.

Frequent Contributor
Posts: 83

Re: Generate executable SAS code

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
Posts: 17,785

Re: Generate executable SAS code

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.

Occasional Contributor
Posts: 9

Re: Generate executable SAS code

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.

 

Thanks,

Tushar

Regular Contributor
Posts: 181

Re: Generate executable SAS code

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

Ask a Question
Discussion stats
  • 8 replies
  • 219 views
  • 6 likes
  • 8 in conversation