In SAS Studio, Snippets are located on the left-hand navigation pane. Code snippets are useful for providing example code for performing various tasks. As of the stable 2025.09 release, snippets are now added as embedded program steps to your SAS Studio Flow. Embedded programs are stored within the flow itself. You can access and edit an embedded program only from within the flow.
I will start with this SAS Studio Flow to walk through an example of adding snippets to a SAS Studio Flow.
Select any image to see a larger version.
Mobile users: To view the images, select the "Full" version at the bottom of the page.
I want to add steps to this flow, so that the output table CARS_INFO is written to an in-memory CAS table.
The first thing I need to do is to find the snippet I want to use to create a CAS session and create SAS librefs for my caslibs. The Snippet that meets that criteria is Generate SAS librefs for caslibs listed under Viya Foundation → Cloud Analytic Services on the Snippets navigation pane of SAS Studio.
Note: I right-clicked on the snippet and selected the option Open as text to view its code.
Now, that I have selected the snippet I want, I right-click and select the option Add to flow. This adds the snippet as an embedded program node to the flow file.
Since I want this code to run before my existing flow in the Cars Info swimlane, I adjust the swimlane order and give it a name. I also save the changes to my flow file.
Next, I add the Delete Table or File from caslib snippet to the flow and rename the new swimlane. I am doing this to prevent any issues if I re-run this flow in the future and the table already exists in my CAS library.
I click on the Delete Table or File from caslib code step in the flow to view its code.
I change the placeholders for “tableName” and “sourceCaslib” to the values needed for my flow and save it.
Next, I drag the Load Data to caslib snippet to my Write Table to CAS and Terminate Session swimlane.
I click on the Load Data to caslib code step in the flow to view its code. It has three examples for loading data to a caslib. For the purposes of my flow, I want to use the second code block.
Therefore, I delete the other two code blocks.
Then, I change the placeholders for “library”, “tableName”, “myCaslib”, and “targetTableName” to the values needed for my flow. I add the command promote to promote the table to in-memory in CAS and save it.
Finally, I drag the Terminate CAS Session snippet to the Write Table to CAS and Terminate Session swimlane on my flow and view its code. No code changes are needed for my flow.
I save and run the flow.
I navigate to SAS Data Explorer to view the resulting CARS_INFO table loaded into memory in my DM CAS library.
Using code snippets is helpful to use as a reusable template for any custom code needed for your SAS Studio Flows. As of the stable 2025.09 release, code Snippets from the left-hand navigation pane of SAS Studio are now added as embedded program steps to your SAS Studio Flow. For more information, refer to the documentation.
Find more articles from SAS Global Enablement and Learning here.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.