A few weeks ago, HoppyFully Brewing Co. — a fictional distributor used as a testbed — needed a way to turn a pile of ad hoc delivery orders into an optimized truck route with time windows. The optimization itself already existed: a mature SAS program that solves a vehicle routing problem with time windows (VRPTW) using SAS Viya's network optimization capabilities. What's missing was the front door — a simple way for someone to enter orders and get routes back, without standing up a separate backend, database, or hosting environment. This post walks through how that app came together, working with Claude inside SAS Viya itself.

Connecting Claude to Viya

The starting point was the Model Context Protocol, or MCP, which exposes a set of tools that let Claude talk directly to a running Viya environment: submitting SAS code for execution, listing and downloading files, querying CAS tables, and checking on compute sessions and jobs. In practice, this meant Claude could act as a developer with real hands on the environment — writing a SAS program, running it, reading the log, and iterating — the same loop a person would go through in SAS Studio, but conversational.

That connection mattered for a design decision made early on: rather than building a separate web server, the app itself would be hosted inside Viya's own Files Service. Every file — the HTML page, its stylesheet, its JavaScript — lives as a file object in Viya and is served back over the same domain the browser is already talking to. That "same-origin" trick avoids a whole category of cross-origin (CORS) headaches that show up the moment a web app tries to call a separate API server, and it means there's nothing extra to deploy or maintain outside of Viya.

Designing the app itself

The interface itself is intentionally plain: a single order screen. One panel lets a customer pick beer styles, pack sizes, and quantities; the other collects delivery details — address, customer type, and a delivery time window. Submitting an order pushes it into the browser's local memory and, behind the scenes, syncs it to CAS tables in Viya. Below is an "Operations" section with two buttons: one to run the routing optimization, one to reset everything and start over. Once routing has run, a Results panel appears showing the solved routes.

Keeping this to plain HTML, CSS, and JavaScript — no framework, no build step — was a deliberate choice. It keeps the whole thing inspectable as a handful of files sitting in Viya's Files Service, and it means the app can be updated by simply replacing those files' contents, which is exactly the loop Claude used throughout development: write the code to create the web app and integrate it to SAS Viya, deploy it as a file update, verify it downloaded correctly, and check the result live in the browser.

Talking to CAS

The mechanism for getting order data into SAS is simple by design. Rather than building an API layer, the browser submits a small SAS program directly to a Viya compute session through the Compute service's REST endpoints. That program embeds the order data as inline SAS DATALINES, reads it into two tables — one for customers, one for order line items — and saves them into CASUSER with promote=yes, so the tables are immediately visible to any other session on the server, not just the browser's own. Before every push, the app first drops any existing versions of those two tables, so each "Submit order" and each "Reset" leaves CAS in a clean, predictable state rather than accumulating stale data. As the web app can be used by many users at the same time, all data is saved in CASUSER, so each user sees its own orders, routings and maps.

Running the routing solver

Once orders are collected, clicking "Simulate the optimal routing" submits a second, larger SAS program to that same compute session. After re-pushing the current orders, it uses %include to run the existing VRPTW solver program unchanged — the app doesn't reimplement any optimization logic, it just triggers the program that already exists on the server's file system, pointed at the CAS tables that were just populated. That program does the real work: building the network model, applying time-window lower and upper constraints, average speed, time to load and unload the goods, vehicle capacity, and produces an optimized route assignment as a CAS table, VRP_SOLUTION, along with an interactive route map written out as an HTML file with all itineraries.



Getting the results back to the browser

This is the part that took the most iteration. A compute session's REST API doesn't hand back a table as a tidy JSON payload by default — the practical channel is the session's own log. So, the SAS code sorts the solution table by route and stop sequence, then writes each row out as a specially tagged log line (ROWCSV:) that the JavaScript on the other end knows to scan for and parse into rows for the on-screen table, complete with arrival and departure times, service windows, and travel times for each stop.



The route map took a similar approach but needed an extra trick. Viya's log has a fixed line-length limit, and the map file — a self-contained Leaflet-based HTML page with an embedded route — has plenty of lines longer than that. The fix was to have SAS chunk every line into short pieces tagged so the browser could stitch them back into an exact reconstruction of the original file, rather than losing anything to truncation.

The bigger point

What made this workable wasn't any single clever trick, but the tight loop of writing code, deploying it, and verifying it against the live environment, with a person steering priorities and approving each change along the way. It's a pattern that will generalize well beyond the vehicle routing problem with time window showed here: any existing SAS program for optimization, forecasting, econometrics, or even predictive modeling can gain a lightweight, purpose-built front end this way, hosted entirely inside Viya, with no separate infrastructure to manage. This front end can be seen as an excellent approach to simulate and visualize SAS programs outcomes in a very interactive and user friendly fashion.

The division of labor is what made that loop fast. The optimization model, the business rules and the final say stayed with the person who owns them. Claude took on the development that usually slows down projects like this: REST calls, security tokens, deployment scripts, and all the checks that confirm each change was actually comitted. Nothing runs against Viya without the code and the reasoning being shown first, and most important, approved. This keeps the entire work very transparent. And the best part: each obstacle along the way became a documented pattern, ready for the next project or application.

There is still room to grow, as always. The model could re-optimize as new orders arrive during the day, combining pickups and deliveries, or size the fleet from typical demand. None of this requires rethinking the architecture, only modifications to the SAS program and eventually a few more fields and checks to the web application.

The broader takeaway is that the front end no longer has to be the expensive part of putting a model in front of the people who use it. Many organizations already own SAS programs that answer important  business questions but only reach whoever can run the code. With Claude connected to SAS Viya through SAS Viya MCP Server, and a person approving each step, those programs can become purpose-built apps in days rather than months, hosted where the data and models already live.

Learn more

Share

About Author

Carlos Pinheiro

Distinguished Data Scientist

Dr. Carlos Pinheiro is a Distinguished Data Scientist at SAS, U.S., and an Adjunct Professor at SKEMA Business School, U.S. Dr. Pinheiro has a B.Sc. in Applied Mathematics and Computer Science, a M.Sc. in Computing and holds a D.Sc. in Engineering from Federal University of Rio de Janeiro (2005). He has accomplished a series of Post-Doctoral research terms in different fields, such as in Optimization at IMPA, Brazil (2006-2007), in Social Network Analysis at Dublin City University, Ireland (2008-2009), in Transportation Systems at Université de Savoie, France (2012), in Urban Mobility and Dynamic Social Networks at Katholieke Universiteit Leuven, Belgium (2013-2014) and in Urban Mobility and Multi-modal Traffic at Fundação Getúlio Vargas, Brazil (2014-1015). He has published several papers in international journals and conferences, is recipient of U.S. Patent, and author of the books Network Science: Analysis and Optimization Algorithms for Real-World Applications (2022, Wiley), Introduction to Statistical and Machine Learning Methods for Data Science (2021, SAS), Heuristics in Analytics: A Practical Perspective of What Influence Our Analytical World (2014, Wiley) and Social Network Analysis in Telecommunications (2011, Wiley).

Related Posts

Leave A Reply