Modernizing from SAS 9.4 to Viya with SAS Managed Cloud Services
Recent Library Articles
Modernizing from SAS 9.4 to Viya takes more than a cloud move—it requires a new operating model. This article explains why lift-and-shift falls short and how SAS Managed Cloud Services helps organizations modernize faster, reduce complexity, and improve outcomes.
Already a SAS Viya user? Then you know you’ve got a wealth of capabilities at your fingertips. We’ll explore those together, giving you access to all the insights you’ll need. Join us on December 10 at 11 a.m. ET.
Animate a SAS series plot with a date loop and the GIF printer driver
In my article Data-Driven Line Colors in PROC SGPLOT with a DATA ATTRIBUTE MAP I asked what the September 1 water level at Lake Neusiedl might be if, starting on May 9, 2022, it followed the same pattern of change as in a historical year.
That gives us one chart. What if we ask the same question on May 10? Or on June 1?
This article explains how you can use the SAS animated GIF printer driver to create animated charts using the SPLOT procedure.
s the cutoff moves from May 9 to August 31, 2022, the observed line grows and the September 1 scenarios are recalculated and recolored
This animation doesn’t simply reveal more points on fixed lines. Each frame recalculates the scenarios. A later cutoff gives us a new observed starting level and a shorter stretch of each historical season to replay. September 1 stays the comparison date, but the result for that date can change enough to move a line into another color category.
The data and programs for this example can be download from my Git Respository here. There you find the programs that generate this graph (GRPH_AnimWaterLevelPlot.sas) as well as the underlying data (CreateData_DailyWaterLevel.sas).
This article explains the necessary steps for the animated GIF printer driver and the %DO LOOP. For the individual graphs itself, it uses program GRPH_DataDrivenLineColors.sas, which is explained in article Data-Driven Line Colors in PROC SGPLOT with a DATA ATTRIBUTE MAP.
Introduction and Business Background
Static charts are often sufficient for reporting. However, some analytical processes are inherently dynamic. Forecasts evolve, uncertainty changes, simulations converge, and new observations continuously reshape our understanding of possible future outcomes.
In those situations, animation can reveal patterns that are difficult to spot in a sequence of static charts.
SAS provides built-in support for animated GIF generation through the ODS Animated GIF driver. By combining ODS Graphics, PROC SGPLOT and a simple macro loop, it is possible to create highly informative animated visualisations directly in SAS.
This article demonstrates the technique using a water-level scenario model for Lake Neusiedl that recalculates future scenarios every day and assembles the resulting charts into a single animated GIF. The overall approach is based on the example presented in my webinar on animated SAS graphics
Why Animated Graphics?
Animation is particularly valuable when change itself contains information.
Examples include:
Forecast updates
Climate scenarios
Monte Carlo simulations
Demand forecasting
Process monitoring
Hydrological modelling
Risk assessment
Movement can often communicate evolving situations more effectively than a collection of static graphics.
Step 0 - Prework: Provide the program that generates an individual graph
This program can be found in "GRPH_DataDrivenLineColors.sas" explained in article Data-Driven Line Colors in PROC SGPLOT with a DATA ATTRIBUTE MAP. Open this program and use the code at steps 1-5. Do not use the code shown at steps 0, as this specifies CUTDATE for a single date only.
Either copy this program it inside the macro loop of Step 3 of the program "GRPH_AnimWaterLevelPlot.sas" which is described here in this article
or create a macro %macro DataDrivenLineGraph; and copy it between there and end it with a %mend; statement
Step 1 - Define the Animation Macro
%macro Water_Level_Anim(from,till,anim_duration=0.5);
from and till are the first and last cutoff dates, both included.
anim_duration is the time each frame stays on screen, in seconds. The macro defaults to half a second.
Step 2: Open a GIF destination and start the animated GIF driver
/***********************************************************************************
*** Step 2 - Set Init Options
**********************************************************************************/
options papersize=('28 cm', '20 cm') printerpath=gif animation=start
animduration=&anim_duration. animloop=yes noanimoverlay;
%let path = /export/viya/homes/gerhard/SAS_Files;
ods printer file="&path/WaterLevel_LinePlot.gif";
ods graphics /height=20cm width=28cm imagefmt=GIF;;
PRINTERPATH=GIF picks the GIF printer driver, and
ANIMATION=START tells it to start an animation sequence.
ANIMDURATION= controls the delay per frame.
ANIMLOOP=YES repeats playback of the finished GIF; that’s separate from the SAS loop that generates the charts.
NOANIMOVERLAY plays the frames sequentially rather than drawing one over another.
PAPERSIZE and ODS GRAPHICS request matching dimensions: 28 cm wide and 20 cm high.
ODS PRINTER FILE= opens the output file once, before the loop. With this destination, each output page becomes a frame.
Note that setting IMAGEFMT=GIF alone doesn’t create the animated sequence.
Folder with WRITE access
You need to have write access to a library at the server where your SAS Session is running. In the folder the final .GIF file will the saved.
In my example this is the folder /export/viya/homes/gerhard/SAS_Files. If you are working from a local PC it should be easy to select such a path. If you are working at a server, ask you administrator that you need a folder in the file system.
Step 3 - Loop over days and create the GRAPH
3.1 Calculate the number of FRAMES for the animation
/***********************************************************************************
*** Step 3 - Loop over Dates and create Graphs
**********************************************************************************/
data _null_;
call symput ("AnimDays","&till."d - "&from."d); *** No need to add 1 because loop starts with 0;
run;
SAS dates are day counts, so subtracting the start date from the end date gives the number of days between them. For May 9 through August 31, AnimDays is 114 . Think of it as the last offset, not the number of frames. The first date has offset 0 ; the last has offset 114 . Since %DO includes both bounds, that gives 115 daily iterations.
3.2 Loop over the DAYS and draw each individual chart
For each of those cutoffs, %DataDrivenLineGraph looks up the new observed starting level, calculates historical changes from the new matching calendar day, rebuilds the September 1 attribute map, and draws the chart. If a scenario changes color, its September 1 result has moved into a different category. The same rules apply in every frame.
Code element "&from"d + &i advances the counter inside the %DO LOOP.
%do i = 0 %to &AnimDays;
data _null_;
call symput ("Cutdate",put("&from"d + &i,date9.));
run;
%DataDrivenLineGraph; *** To define this macro use Code code from STEP 1-5 (not Step 0!!!) from program "GRPH_DataDrivenLineColors.sas";
*** Alternatively paste the code from STEP 1-5 (not Step 0!!!) from program "GRPH_DataDrivenLineColors.sas" here.;
%end; *** Do Loop;
For each of those cutoffs, %DataDrivenLineGraph looks up the new observed starting level, calculates historical changes from the new matching calendar day, rebuilds the September 1 attribute map, and draws the chart. If a scenario changes color, its September 1 result has moved into a different category. The same rules apply in every frame.
Why use a macro loop instead of a BY statement? BY -group processing is an option when the data for each frame is already prepared. Here, moving the cutoff changes the inputs to the calculation, so I rerun the calculation and the plot together
In your individual application you would paste the code inside this macro loop. The code can contain calculations and data preparation that is needed to generate the plot data for that specific point in time.
Step 4: Stop the animation and close the output
/***********************************************************************************
*** Step 4 - Set Closing Options
**********************************************************************************/
options printerpath=gif animation=stop;
ods printer close;
%mend Water_Level_Anim;
Finally you close the GIF AnimPrinter and the GIF file is written to the destination you specified.
These closing statements belong after the loop. ANIMATION=STOP ends the animated sequence, and ODS PRINTER CLOSE closes the output file. Opening and closing the destination around the entire loop gives you one GIF containing the full sequence.
You navigate there and download the GIF file and open it in your browser. You should now see the animation of the line charts.
Run the Example
title;
options mprint;
%Water_Level_Anim(09MAY2022, 31AUG2022,anim_duration=0.25);
TITLE; clears any title left over from earlier work. OPTIONS MPRINT writes the SAS statements generated by the macros to the log, which is useful for checking that the cutoff date actually changes in the generated code.
The example sets a quarter-second delay and covers 115 dates. If each call produces exactly one page in ODS PRINTER , the GIF has 115 frames.
Usage Hint
Before generating the full season, I’d check a short range first. If the cutoff repeats, look for a Cutdate assignment inside the chart macro that overrides the loop. If the GIF alternates between different chart types, check whether the quantile plot is also reaching the printer destination. And watch the axes: Part 1 sets the y-axis limits, but its WHERE clause filters the x-axis data without fixing the displayed x-axis endpoints. A shifting scale can make the scenarios look as if they changed more than they did.
The moving cutoff tells you when the scenario was calculated. The line colors tell you which September 1 outcomes crossed a threshold. That’s what makes this more useful than simply playing a series of charts.
Practical Tips
Here are some useful lessons learned when building animated graphics.
1. Freeze the axes
Always fix axis ranges: e.g.
yaxis min=0.5 max=1.5;
otherwise the graph may jump between frames.
2. Choose a sensible frame speed
For most analytical animations animduration =0.1 - 0.5 provides good results.
3. Verify GIF viewer support
Some image viewers display only the first frame. If the animation appears static, verify that the GIF viewer supports animation.
Conclusion
Creating Animated GIFs in SAS
The Animated GIF driver works by collecting a sequence of graphics and storing them as frames within a GIF file.
The workflow is straightforward:
Start animation mode.
Generate a series of graphs.
Store each graph as a frame.
Stop animation mode.
Save the GIF.
The Heart of the Actual Solution: The Macro Loop
Most examples of the SAS Animated GIF driver focus on animating existing data. This example demonstrates something more powerful: animating a complete analytical workflow. Each frame is the result of an entirely new analytical calculation. The animation loop therefore becomes the centrepiece of the solution.
%do i = 0 %to &AnimDays;
During every iteration:
A new cut-off date is selected.
Water-level scenarios are rebuilt.
Historical years are shifted.
Risk categories are recalculated.
A new graph is generated.
The GIF therefore visualizes the evolution of the analysis itself.
As the cut-off date progresses through the year, the viewer can observe how the entire range of possible future water-level developments evolves.
Some scenarios disappear.
Others become increasingly likely.
Risk classifications change.
Uncertainty narrows.
The resulting animation communicates all of this information far more effectively than a collection of static charts.
The final result shown in the webinar demonstrates how the range of possible outcomes changes throughout the season
That ability to animate analysis, rather than just data, is where the Animated GIF driver becomes truly valuable.
References and Links
The data and programs for this example can be download from my Git Respository here.
Article The water level on Lake Neusiedl in 2022 — viewpoints of a sailor and statistician at medium.com
Connected Article: Data-Driven Line Colors in PROC SGPLOT with a DATA ATTRIBUTE MAP.
More SAS Community articles from Gerhard
Youtube: Simulation Scenarios for the Water Level at Lake Neusiedl in 2020
... View more
Hello,
On our SAS Viya platform, we use SAS Environment Manager to create job requests and job flows for scheduling. A single job flow can contain multiple job requests as dependencies, which may run either sequentially or in parallel.
We have a requirement to back up all Job Flows so that they can be restored if they are accidently deleted from SAS environment manager. Im using sas cli to export the job flow
sas-viya transfer packages export --name "xxxx" --resource-uri "/jobFlowScheduling/flows/xxx" --include-dependencies
sas-viya transfer packages download --id <package_id> --file xxx.json
For testing purpose, I deleted the original job flow from the same environment and then imported the json file using import feature in SAS environment manager. The import is successful and the job flow reappeared in SAS Environment manager.
But when I view or edit the flow, it throws me an error that "Some dependencies are missed for the flow instance". During the import, only the job flow itself was listed, and none of the job requests that belong to it.
Does this mean it is not possible to export and import a job flow together with its job requests in SAS Viya? Please let me know.
... View more
Want to build an A/B test and interpret the results? Watch SAS experts demonstrate how it's done.
About the Webinar
A/B testing eliminates the guesswork from understanding your audience and helps you make data-driven decisions that improve customer journeys. But to get real value from A/B testing, you need to know when and how to set up the right test.
What if that’s where the guesswork begins?
In this 30-minute session, SAS experts will demonstrate how A/B testing works in SAS Customer Intelligence 360 – from setting up a test to understanding the results and using those insights to guide your customer journeys.
Q&A
Once CI 360 determines that one path has won, what happens to customers who enter the journey afterwards?
Once CI 360 identifies the winning path, subsequent customers reaching the A/B test are automatically directed to that winning path. Customers already progressing through a test variant continue on their originally assigned path.
Do marketers have to wait until the test is complete before they can see how each variant is performing?
Thanks to the Optimization tab of the Insights section of an active scheduled journey marketers can monitor how each variant is performing while the A/B test is running. They don't need to wait for completion. CI 360 continues collecting results until the test reaches its decision criteria, at which point it determines the outcome and can automatically route future customers to the winning path.
Can a test include different channels?
Absolutely, the AB tests you can run in CI 360 scheduled journeys can include any of the tasks that work in scheduled journeys, from custom tasks (for 3rd party solutions) to emails, push notifications, ads tasks or SMS.
How do you avoid testing things just because you can? What makes a good hypothesis for a journey A/B test?
A good A/B test starts with curiosity, but it should be grounded in a business question or customer insight, not simply in something that happens to be easy to test.
Ask: What do we believe about our customers or journey, and what evidence would help us validate that belief?
Data can help here. Analysis of customer behaviours and experiences can reveal patterns associated with outcomes such as engagement or conversion. Those insights can give marketers meaningful opportunities to experiment and help move hypothesis development from “What can we test?” to What is worth testing?”
If the outcome won’t influence a decision or teach you something useful, it’s probably not a strong candidate for an A/B test.
The goal is to replace ambiguity and gut feel with empirical evidence that improves future journey decisions.
Access to the On Demand recording: Optimize Customer Journeys with A/B Testing in SAS Customer Intelligence 360 | SAS
Want more CI 360 tips? Be sure to subscribe to the SAS Customer Intelligence Library for more inspiration from experts on how to get the most out of CI 360.
Resources:
How is SAS Customer Intelligence 360 Marketing AI Redefining Marketing? | SAS
Using the AB Test Nodes in Scheduled Journeys for SAS Customer Intelligence 360
Guided Path: A-B Testing in CI 360 Journeys | SAS
Journeys in SAS® Customer Intelligence 360: Move From Email Blasts to Customer-First Orchestration …
... View more
I open SAS.
I submit a macro (just submit it, so nothing happens except it puts the macro into memory). A line in the macro points to a formats library.
I call the macro, so the guts of the macro runs.
When the macro runs it creates a dataset. After running the macro I do a PROC FREQ on that dataset. All the formats are applied correctly.
Then I call the macro again. I do not submit the macro itself again, rather I just call (run) it. I change nothing and I do nothing else. All I do is call the macro a second time.
Then I do that same PROC FREQ mentioned above and this time some...not all, but some...of the formats are not applied.
So the 1st time I run the PROC FREQ I see all words (the formatted values) instead of their underlying numbers.
And the 2nd time I run the PROC FREQ I still see mostly words (the formatted values), but for some of them I see their underlying numbers instead.
And every subsequent time I run it I see the mostly words but some underlying numbers instead.
IOW, it works properly after I open a new SAS session and run it for the first time. And it doesn't work properly every subsequent time I run it.
Any idea?
... View more
How to become a professional and more efficient using SAS Visual Analytics
Let’s get Aggregated with AggregateTable
Part 4: Let’s investigate how AggregateTable “Group context” options Fixed, Add and Remove categories affects the result.
It’s time for the fourth and final part of this mini-series. I have decided not to do a video, because there is little to visualize - just a simple two-column list table. What matters is what happens behind the scenes: understanding how these options affect the result.
These options can be difficult to explain, so I created a simplified table to show how each one affects the result.
The examples may not be realistic and could be solved with other AggregateTable settings. Their purpose is to compare the same function definition using different “Group context” options.
To review other scenarios using AggregateTable and different “Group context” options, see other great published articles for more use case examples. See links and references at the end of this article.
A summary PDF for the entire “Let's get Aggregated with AggregateTable” series is available for download—see header (upper left corner) of this article. This PDF contains all my use cases and solutions for you to explore. Enjoy 🙂
Introduction
This is the AggregateTable function definition (Figure 1) we will be using in all my examples below and the only thing we will change is the “Group context” option.
Figure 1
What does these "Group context” options do?
Here is a short description/explanation:
Choose Fixed when you want to specify categories explicitly
Choose Add when you want to retain categories visualized and include (Add) other categories into your AggregateTable calculation
Choose Remove when you want to remove categories in your AggregateTable calculation (of course, displayed categories will still affect your result)
This is the simplified table (Figure 2), that contains three customers with multiple orders across 2021 and 2022, and each order has an order value. A transaction date is included only to make my example data more realistic.
Figure 2
Group context option "Add categories"
Use-case description and challenge
Our data scientists are analyzing customer purchase patterns, and they are looking into how to define different purchase patterns KPI’s.
One of these KPI’s is to calculate average order value, which is based on max order value for each individual customer and transaction year. Sounds straightforward, right. However, this KPI must be displayed for each individual year only (Figure 3).
This is the correct and expected result:
Figure 3
Remember, visualized categories does have an affect on the result. Although customer is not shown in the list table (Figure 3), it is still needed for the calculation.
This is the AggregateTable function solution for our use case (Figure4):
Figure 4
Let’s take a closer look into what is going on here...
Figure 5
Let’s start by looking at the list table above (Figure 5), which displays columns Transaction Year and Average on Max Order Value for each Customer. Transaction Year therefore groups the result by year, as it is displayed in our list table. However, column Customer is also needed for the calculation, but we do not want to display it.
That’s why we can use group context option "Add categories“, that adds column Customer into the AggegateTable calculation. As we are also displaying Transaction Year, our first aggregation (Aggregation 1) will now pick max order value for each customer and year.
Finally, Final aggregation will then calculate average for each individual year.
So, this is how this use case could be solved using group context option "Add categories". Let’s investigate the other options as well and what affect it will have on the result.
Group context option "Remove categories"
What will happen if we use group context option "Remove categories" instead? Well, here is the result:
Figure 6
That is quite a difference compared with our previous result, so what is going on here?
Figure 7
As we now use option “Remove categories”, Customer is removed from the calculation. As the list table displays Transaction Year (Figure 6), our first aggregation (Aggregation 1) will now just pick max order value for each year and Final aggregation will then calculate average for each individual year
Group context option "Fixed categories"
OK, what will happen if we use group context option "Fixed categories" instead? Here is our new list table result:
Figure 8
This result might look very weird (Figure 8), so let’s take a closer look into what happened to our result using option Fixed categories.
Figure 9
Remember, option "Fixed categories" require you to explicitly specify which categories you want to use.
So, in this case, first aggregation (Aggregation 1) will only take the maximum order value for each customer, even if two transaction years are displayed. Again, Final aggregation will then calculate average for each individual year.
Summary and Conclusion
Part 4 brings this mini-series to an end. If you missed any of the previous videos, here are the links:
Part 1 - AggregateTable function introduction and two simple use-cases, which I think is a good way to get you started using this fantastic function.
Click here to view the video…
Part 2 - We continue our journey of exploring this amazing function by looking at different percentage of sub-totals examples. We will look at different scenarios where we use the AggregateTable function with different options to meet our end-user requirements.
Click here to view the video…
Part 3 - Let's take a look at how we can work with nested and multiple aggregations when using the AggregateTable function. We are going to look at a use-case where we want to benchmark an average, which is based on another aggregation.
Click here to view the video…
As shown in this mini-series, AggregateTable is a very powerful and flexible function in SAS Visual Analytics. Just summarize its value and power...
Solves many aggregation challenges
Ideal for benchmark use cases
Reduces the need to pre-prepare data, specifically for benchmark use-cases
Keeps flexibility in SAS Visual Analytics
Even more powerful with Enhanced Parameters (SAS Viya 4 only)
Other great articles and use cases using the AggregateTable function:
SAS Visual Analytics Advanced Calculations (part 2 of 4): AggregateTable (by Renato_sas)
https://communities.sas.com/t5/SAS-Communities-Library/SAS-Visual-Analytics-Advanced-Calculations-part-2-of-4/ta-p/538541
SAS Visual Analytics: Understanding the AggregateTable Function for Beginners (by NithinRamu)
https://communities.sas.com/t5/SAS-Communities-Library/SAS-Visual-Analytics-Understanding-the-AggregateTable-Function/ta-p/959903
I truly hope you enjoyed this mini-series and learned more about what AggregateTable can do and how to use it. You never know, but you might sit there with an use case right now that can be solved using AggregateTable.
Take care, and see you next time 😊
... View more