SAS Enterprise Guide

Desktop productivity for business analysts and programmers
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MarkusWeick
Barite | Level 11

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

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
1 ACCEPTED SOLUTION

Accepted Solutions
AlanC
Barite | Level 11

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.

 

 

https://github.com/savian-net

View solution in original post

10 REPLIES 10
AlanC
Barite | Level 11

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.

https://github.com/savian-net
MarkusWeick
Barite | Level 11

@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

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
MarkusWeick
Barite | Level 11

@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

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
AlanC
Barite | Level 11

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.

 

 

https://github.com/savian-net
MarkusWeick
Barite | Level 11

@AlanC: Hi Alan, thankyou very much. Exactly what I was looking for!

Best Regards

Markus

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
ChrisHemedinger
Community Manager

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.

Register for SAS Innovate 2025!! The premier event for SAS users, May 6-9 in Orlando FL. Sign up now for the best deals!
MarkusWeick
Barite | Level 11

Thankyou Chris!

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles
AlanC
Barite | Level 11

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;

 

 

 

https://github.com/savian-net
MarkusWeick
Barite | Level 11

Thanks Alan!

Please help to keep the community friendly.
Like posts you agree with or like. Mark helpful answers as “accepted solutions”. Generally have a look at https://communities.sas.com/t5/Getting-Started/tkb-p/community_articles

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1666 views
  • 6 likes
  • 3 in conversation