BookmarkSubscribeRSS Feed

Preamble and Postamble Code in SAS Studio Flows

Started 2 weeks ago by
Modified 2 weeks ago by
Views 166

In a SAS Studio Flow, it's common to use SAS Program nodes to handle preliminary tasks like connecting to libraries, enabling SASTRACE log output, and more. Similarly, you may need to handle tasks at the end of your flows as well, like terminating a CAS session or resetting SAS system options. What if you could handle these tasks directly within the nodes you need them for? With the SAS Viya 2026.03 stable release, you can! For any SAS Studio Flow step node, you can specify custom code to run immediately before or after the step runs during execution.

 

In this post, I'll discuss the new preamble and postamble code options in SAS Studio Flows and how they relate to traditional DI Studio features. I'll also demonstrate three example use cases: adding multi-level titles to reports, defining SAS libraries, and connecting to a CAS session. Keep reading to learn about how to optimize your flow canvas with preamble and postamble code!

 

Adding Preamble and Postamble Code to a Flow Node

 

In SAS Data Integration Studio, you can add user-written code to execute immediately before or after a job or transformation is executed. This option is configurable on the Precode and Postcode tab in the properties window for the job or transformation that is being updated. The example shown below is sourced from the SAS Data Integration Studio documentation.

 

grbarn_precode_1.png

Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.

 

The 2026.03 SAS Viya stable release enables adding custom SAS code to run before and after any specific node in a flow. This option can be configured on the Node tab for any flow step (under Custom code). For more information on this feature, review the SAS documentation.

 

grbarn_precode_2.png

 

Let's go through a few examples of use cases for this feature.

 

Example 1: Adding Multi-Level Titles to Reports

 

When visualizing data with the Bar Chart step, the default results do not include a title.

 

grbarn_precode_3.png

 

While the step has an option to include a title, you can only include a high-level title (on the Options tab).

 

grbarn_precode_4.png

 

grbarn_precode_5.png

 

If I want to add a main title and a subtitle, I can add some custom code to the Preamble section on the Node tab.

 

grbarn_precode_6.png

 

Now, my results include a title and a subtitle.

 

grbarn_precode_7.png

 

Example 2: Connecting to a SAS Library

 

Sometimes, your flow uses data that is stored in a specific library. If the library definition isn't saved in SAS Studio, you'll have to connect to the library prior to using its data in the flow.

 

When attempting to use the Characterize Data step with a table stored in a user-defined library, my flow fails because I haven't connected to the library yet, so the source table can't be found.

 

grbarn_precode_8.png

 

To fix the issue without adding more nodes to the flow, I can add the library definition to the Preamble section on the Node tab.

 

grbarn_precode_9.png

 

Now, my flow runs successfully!

 

grbarn_precode_10.png

 

Example 3: Working with CAS Data

 

When working with CAS tables in a flow, you'll need to start a CAS session, create or connect to CAS libraries, and sometimes more!

 

Similar to the previous scenario, if you don't do these preliminary tasks, your flow could fail due to not being able to access the source data.

 

grbarn_precode_11.png

 

For this example, I'm going to add preamble and postamble code.

 

First, I'll add preamble code to start a CAS session and assign SAS libraries to all caslibs.

 

grbarn_precode_12.png

 

Then, because I'm creating an output CAS table with this step, I'll add postamble code to list all files and tables in the target caslib after the step executes.

 

grbarn_precode_13.png

 

Now, my flow runs successfully thanks to the preamble code.

 

grbarn_precode_14.png

 

Additionally, I can review the results from the postamble code.

 

grbarn_precode_15.png

 

Summary

 

In this post, I introduced the new preamble and postamble custom code feature for nodes in SAS Studio and demonstrated three use case scenarios. If you want to learn more about new node features in SAS Studio Flows, check out Gemma Robson's post Introducing Parameters and Prompts in SAS Studio Flows.

 

Did you use precode and postcode options in SAS Data Integration Studio? Does this feature help improve your SAS Studio Flows? Share your thoughts, questions, and feedback below!

 

 

Find more articles from SAS Global Enablement and Learning here.

Contributors
Version history
Last update:
2 weeks ago
Updated by:

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Labels