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.
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.
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.
While the step has an option to include a title, you can only include a high-level title (on the Options tab).
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.
Now, my results include a title and a subtitle.
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.
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.
Now, my flow runs successfully!
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.
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.
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.
Now, my flow runs successfully thanks to the preamble code.
Additionally, I can review the results from the postamble code.
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.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.