Welcome back to my "Simplifying SAS Viya" series! In Part 1, we discussed the differences between the Compute and CAS Servers, and Part 2 was all about caslibs. In this post, we'll focus on loading data source files to in-memory tables. I'll cover the differences between server-side and client-side loads, with examples using SAS Viya for Learners 4 (VFL). This free tool is a great resource for educators and students learning SAS Viya, and all code in this post can be run in your VFL environment. All syntax in this blog is applicable in other SAS Viya environments.
In a traditional SAS 9 environment, we work with data source files such as Excel, SAS, CSV, and JSON. You can still work with these files on the Compute server as usual. However, to use data on the CAS Server, you must load the data source files to in-memory tables. This can be done using either a server-side load or a client-side load.
Throughout this post:
These terms are not interchangeable.
In-memory tables are temporary copies of data source files. Data source files remain unchanged on disk.
Jump to instructions on setting up VFL with the data used in this post.
A server-side load is used when the data source file is already in a caslib. Since the file is accessible to the CAS Server, data can be loaded directly into memory for processing using the CASUTIL procedure. This method is recommended for loading large datasets and working with data across other SAS Viya applications.
Currently, airport_traffic_2024.csv is stored in the casuser caslib, making this a server-side file.
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 following example loads airport_traffic_2024.csv into memory as EU_Air_Traffic in the casuser caslib:
PROC CASUTIL;
LOAD CASDATA="airport_traffic_2024.csv"
INCASLIB="casuser"
CASOUT="EU_Air_Traffic"
OUTCASLIB="casuser";
QUIT;
To view the table in the casuser caslib, use the LIST TABLES statement in PROC CASUTIL:
PROC CASUTIL;
LIST TABLES INCASLIB=casuser;
QUIT;
By default, in-memory tables are session scope, meaning they are available only within the current session and are dropped when the CAS session ends. Right now, EU_Air_Traffic is only visible in SAS Studio. To make a table available across SAS Viya applications, use the PROMOTE option, making it global scope:
PROC CASUTIL;
LOAD CASDATA="airport_traffic_2024.csv"
INCASLIB="casuser"
CASOUT="EU_Air_Traffic_Global"
OUTCASLIB="casuser"
PROMOTE;
QUIT;
Now, the table is available in other applications. We can verify this in Visual Analytics.
Navigate to:
Applications menu
Explore and Visualize
New Report
Add Data
Search for EU_Air_Traffic_Global. The table will be visible and available to use for reporting.
A client-side load is used when the data source file is on the Compute server (e.g., in a SAS library or folder path) and needs to be transferred to the CAS Server. This method is great if you are a traditional SAS programmer and want to continue using traditional SAS code to prepare data, then load the data into memory. Once the data is loaded into memory, you can access it in other Viya applications like Visual Analytics for reporting. This method is more resource-intensive, so a server-side load is preferred whenever possible.
There are three ways to perform a client-side load:
This example loads the sashelp.cars dataset into memory as cars_CAS in the casuser caslib:
PROC CASUTIL;
LOAD DATA=sashelp.cars
CASOUT="cars_CAS"
OUTCASLIB="casuser"
PROMOTE;
QUIT;
Airport_traffic_2020.csv is currently a client-side file located in the AirTraffic folder. This example loads airport_traffic_2020.csv into memory and creates EU_Air_2020 in the casuser caslib:
PROC CASUTIL;
LOAD FILE="/export/viya/homes/your_username/AirTraffic/airport_traffic_2020.csv"
CASOUT="EU_Air_2020"
OUTCASLIB="casuser"
PROMOTE;
QUIT;
You can also load data into memory using the DATA step by specifying a libref mapped to a caslib for the output data set. The following example filters the SASHELP.CARS table for cars made by Toyota and writes the results to the in-memory table ToyotaCars_CAS in the casuser caslib.
DATA casuser.ToyotaCars_CAS (PROMOTE=YES);
SET sashelp.cars;
WHERE Make="Toyota";
RUN;
PROC IMPORT can be used to load files like CSVs, TXT or Excel. In the OUT=option, specify a libref that is mapped to a caslib as the library for the output table.
The following example loads airport_traffic_2022.csv into memory as EU_Air_2022 in the casuser caslib.
OPTIONS OBS=1000;
PROC IMPORT DATAFILE="/export/viya/homes/your_username/AirTraffic/airport_traffic_2022.csv"
DBMS=csv
OUT=casuser.EU_Air_2022
REPLACE;
RUN;
OPTIONS OBS=max;
Remember, whether you're performing a server-side load or a client-side load, PROC CASUTIL is the most efficient option for loading files to in-memory tables. In SAS Studio, there is a snippet with PROC CASUTIL syntax for loading a client-side file, SAS table in a library, and server-side file into memory.
To use this snippet, navigate to:
Snippets
Viya Foundation
Cloud Analytic Services
Load Data to caslib
Modify the code in the snippet depending on the use-case.
To work with data in CAS, data source files must be loaded into memory within a caslib. In-memory tables are copies of the original files, which remain unchanged on disk.
All examples were demonstrated in SAS Viya for Learners 4, a powerful and free tool for educators and students to explore SAS Viya capabilities. All syntax is applicable in other SAS Viya environments.
Be on the lookout for the next post in this series- let's continue simplifying SAS Viya!
Simplifying SAS Viya Part 1: Choose Your Server
Simplifying SAS Viya Part 2: What are Caslibs?
To follow along with this post in SAS Viya for Learners 4:
PROC CASUTIL INCASLIB="casuser";
LIST FILES;
QUIT;
For more on SAS Viya for Learners check out these posts:
Find more articles from SAS Global Enablement and Learning here.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.