Have you ever needed to perform the same task repeatedly to process similar data inputs, such as creating sales reports on all the products your company offers, or analyzing sales for every month of the year? Loops allow the same code to be executed repeatedly for situations just like these. However, you may want to loop a flow in SAS Data and AI Studio (formerly SAS Studio) instead of writing blocks of code. With the new Loop step, you can do exactly that!
In this post, I'll demonstrate how to use the Loop step to summarize customer order data by country. I'll discuss creating a control table, parameterizing an inner flow, and building an outer flow that successfully loops the inner flow. Keep reading to learn more about looping your flows!
The Loop Step
In SAS Data Integration (DI) Studio, you can use the Loop transformation to create and run an iterative job. An iterative job is a job with a control loop in which one or more processes are executed multiple times. This is helpful when you need to run the same series of tasks for a variety of input values.
DI Studio iterative job
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 new Loop step, introduced in the 2026.08 SAS Viya stable release, brings the same capability to SAS Data and AI Studio! With the Loop step, you can execute a flow a specified number of times with different parameter values. Additionally, you can choose to run each iteration sequentially or in parallel, with different processing options for each method. For more information on this step, visit the SAS documentation. The Loop step is available with the SAS Data and AI Studio Enterprise (formerly SAS Studio Engineer) license.
In this post, I'll be recreating a DI Studio iterative job (pictured above) in SAS Data and AI Studio.
SAS Data and AI Studio iterative flow
Let's see how to create this product with the Loop step.
Scenario
We want to run a flow that creates summary reports for all customer orders per country.
Source table CUSTORDERS
The country value will be specified through a parameter. We'd like to run this flow for every country that appears in our customer data. We'll achieve this with the Loop step. Before we can dive into using the Loop step, we need to prepare some pre-requisites.
Control Table
To run an iterative flow, you need a control table. The control table has a list of distinct values that will be used in your flow process.
I've created a table called COUNTRIES_CONTROL which stores information about the countries our customers are located in. For each country, the table stores the country code, the full country name, and a compressed version of the country name. Each of these values will be used in the inner flow.
Control table COUNTRIES_CONTROL
Inner Flow
Next, you must create an inner flow that will run for each iteration of the Loop step. To make the flow iterative, your flow must include at least one step that uses a parameter.
My inner flow uses parameters in multiple areas and in multiple ways. Let's review the parameters and where they're implemented.
Inner flow overview
In my flow, I defined three parameters that correlate with my control table columns: CtryCode, Ctry, and CompCtry.
Parameters defined in inner flow (CtryCode, Ctry, and CompCtry)
In the Filter Rows step, I use CtryCode as the filter value to create a subset of customers in a specific country.
Filtering CUSTORDERS for Customer_Country=CtryCode
In the Summary Statistics step, I use &Ctry. to create dynamic titles for the output reports.
Adding dynamic title to Summary Statistics step output with Ctry parameter
Lastly, I use &CompCtry. to name the output table storing the results from the Summary Statistics step. This ensures that there will be individually named output tables for each country.
Naming output table with CompCtry parameter
For more information on parameters, visit the documentation or read Gemma Robson's post "Introducing Parameters and Prompts in SAS Studio Flows".
Now that I've created these prerequisites, I can use the Loop step.
Creating Outer Flow with Loop Step
After connecting the control table to the Loop step, you must specify the inner flow you want to iterate on the Options tab. The file location and name will appear after you've selected the file.
Then, select the iteration execution method. There are four methods available: Parallel - single instance, Parallel - multiple instances, Sequential - single session, and Sequential - multiple sessions. In this example, I've selected Sequential - single session to run my iterations one after another in the compute session in my outer flow. To see a description of all iteration execution methods and how they work, visit the documentation.
If desired, you can also select locations to save the logs and the output from each iteration.
Configure Loop step (specify inner flow location and iteration execution method)
On the Status Conditions tab, you can specify how to handle error conditions. I've selected the default option, which is to abort the flow after completing the current iteration.
Set error handling options on Status Conditions tab of Loop step
Then, you must map the parameters between the control table and the inner flow on the Parameter Mapping tab. For each parameter, I've selected the correlated control table column.
Mapping parameters between control table and inner flow on Parameter Mapping tab of Loop step
Lastly, you can add columns from the control table to the loop's output table (in addition to the automatically generated status columns) on the Status Columns tab. Here, I've added the Country_Code column to the output.
Select columns for loop output table on Status Columns tab of Loop step
Loop Step Output
After the Loop step has been configured, I can run the flow and review my results.
First, I can see that a report was generated for each country in my control table, and each report has a dynamic title.
Report output with dynamic titles
The inner flow also created an output table for each country with the compressed country name, and the outer flow created the LOOP_OUTPUT table. Note: some additional output tables were also created from steps used in the inner flow.
Table output with dynamic table names
Additionally, the log and html output files were automatically created for each iteration and stored in the specified file location.
Log and html output files for each loop iteration
Summary
In this post, I introduced the new Loop step and demonstrated how to successfully create an iterative process in SAS Data and AI Studio Flows. If you want to learn more about this step, visit the documentation.
Do you use the Loop transformation in SAS Data Integration Studio? Did this post help you understand how to create iterative processes in SAS Data and AI Studio Flows? Share your thoughts, questions, and feedback below!
Find more articles from SAS Global Enablement and Learning here.
Visit the Tips & Tricks page for setup guidance, demos, and practical examples that show how Copilot supports your workflows.
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.