Hi, together. When I use the tasks in Enterprise Guide, Code is created. How does this work?
Who knows any articles about it?
Thanks, Markus
EG is written in C# so it will use .NET code to do code gen.
As background, codegen in SAS can be done easily. See this link for my sample code.
https://github.com/savian-net/SasTipsTricks?tab=readme-ov-file#dynamic-code
However, EG uses C#, not SAS, for controlling the app environment:
For C#, when you select items on a UI, we can detect their state and write the SAS code to do that action. That code is then submitted to SAS using IntTech.
Here is some sample C# code to illustrate the code gen. This is then submitted to SAS Integration Technologies, via C#, in a call that is something (syn?) like ws.Submit(_sb.ToString()):
_sb.AppendLine($@" filename resp 'c:\temp\{svc.Name}.json';"); _sb.AppendLine(); _sb.AppendLine($" proc http"); _sb.AppendLine($" method=\"{svc.Verb}\""); _sb.AppendLine($" url = \"http://&SERVER.:&PORT./Sas/{svc.Name}{parms.urlParms}\""); _sb.AppendLine($" out= resp;"); _sb.AppendLine($" run;");
I use this technique a lot, C# to SAS, for web services and utility functions. Chris H got me started on it 25 yrs ago.
There are loads of articles, videos, etc. What are you trying to find out?
When a task has code, the code is stored in the egp project file. When you run the task, the code is submitted to SAS (local or server) and the output is streamed to the output window.
If you want to get the code from the file, change the file name's extension to .zip vs .egp and then open it up.
@AlanC: Hi Alan, thanks for your reply. Please have a look at my reply to Chris below for the full background. I am interested in the code generation logic Chris mentioned.
Best Regards,
Markus
Hi Markus,
When you make selections in the EG tasks, EG stores those settings in the EG project. When it comes time to run your project, the EG task builds the SAS code according to the settings. For example, if you run the Logistic Regression task and select that you want the ROC chart, the task generates the appropriate PLOTS= options on the PROC LOGISTIC statement.
There is a lot of code generation logic built into the tasks themselves, and this is used by EG to generate the code for each task as it runs in your flow.
@ChrisHemedinger: Hi Chris, Thanks for your reply. I am interested in the code generation logic, which generates the code. Not so much for me. But yesterday I gave an introduction to SAS for the new joiners in our company. And the question how the code is generated arose. I would like to give an answer to my rather technical oriented colleagues.
Best Regards
Markus
EG is written in C# so it will use .NET code to do code gen.
As background, codegen in SAS can be done easily. See this link for my sample code.
https://github.com/savian-net/SasTipsTricks?tab=readme-ov-file#dynamic-code
However, EG uses C#, not SAS, for controlling the app environment:
For C#, when you select items on a UI, we can detect their state and write the SAS code to do that action. That code is then submitted to SAS using IntTech.
Here is some sample C# code to illustrate the code gen. This is then submitted to SAS Integration Technologies, via C#, in a call that is something (syn?) like ws.Submit(_sb.ToString()):
_sb.AppendLine($@" filename resp 'c:\temp\{svc.Name}.json';"); _sb.AppendLine(); _sb.AppendLine($" proc http"); _sb.AppendLine($" method=\"{svc.Verb}\""); _sb.AppendLine($" url = \"http://&SERVER.:&PORT./Sas/{svc.Name}{parms.urlParms}\""); _sb.AppendLine($" out= resp;"); _sb.AppendLine($" run;");
I use this technique a lot, C# to SAS, for web services and utility functions. Chris H got me started on it 25 yrs ago.
@AlanC: Hi Alan, thankyou very much. Exactly what I was looking for!
Best Regards
Markus
Hi Markus,
If you want to see the source code for a "real task", check out the samples I have on GitHub. Here's one:
https://github.com/cjdinger/SAS.Tasks.Cardinality
This particular task is simple (described here) -- it's a UI with a couple of options that feeds into a SAS macro. That's one way to build these, or you can use more explicit string-builder logic as @AlanC showed.
Thankyou Chris!
As Chris states, there are a number of ways to do this codegen/SAS submission. I showed you stringbuilder but I have also used T4 templates, macro substitution,etc. Use any method to get SAS code in the shape needed and then ready for run.
BTW, you can also create your own EG Tasks and do your own code submission. I have done it multiple times for companies. They need a specific block of SAS code submitted that had a complex, custom UI in EG. You can gen it or have SAS code and substitute key words (similar to what Chris mentioned). SAS uses ampersands but you can do your own, like CDATA:
data [[OUTDATA]]; set [INDATA]]; if age < [[USER_SELECTED_AGE]] then... ...
run;
Thanks Alan!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.