BookmarkSubscribeRSS Feed
Piku
Obsidian | Level 7

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

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

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

Astounding
PROC Star

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? 

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

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

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

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

 

Thanks,

Tushar

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 3251 views
  • 6 likes
  • 8 in conversation