SAS Communities Library

We’re smarter together. Learn from this collection of community knowledge and add your expertise.
BookmarkSubscribeRSS Feed

Simplifying SAS Viya Part 3: Loading Data into Memory Using SAS Viya for Learners

Started ‎03-06-2025 by
Modified ‎03-06-2025 by
Views 891

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.

 

Working with Data in SAS Viya

 

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:

 

  • The term "file" refers exclusively to a data source file.
  • The term "table" or "in-memory table" refers exclusively to a data source file that has been loaded into memory.

 

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.

 

Server-Side Load

 

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.

 

Example: Server-Side Load Using PROC CASUTIL

 

Currently, airport_traffic_2024.csv is stored in the casuser caslib, making this a server-side file.

 

01_CJC_3-1024x366.png

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;
  • CASDATA= defines the data source file to load into memory.
  • INCASLIB= defines the caslib the data source file is currently in.
  • CASOUT= defines the name of the new in-memory table.
  • OUTCASLIB= defines the caslib the new in-memory table will be in. This caslib does not have to match the caslib the data source file is currently in.

 

02_CJC_4.png

 

To view the table in the casuser caslib, use the LIST TABLES statement in PROC CASUTIL:

 

PROC CASUTIL;
   LIST TABLES INCASLIB=casuser;
QUIT;

 

03_CJC_5-1024x213.png

 

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

 

04_CJC_13.png

 

Explore and Visualize

 

05_CJC_14-202x300.png

 

New Report

 

06_CJC_15-1024x251.png

 

Add Data

 

06a_CJC_16.png

 

Search for EU_Air_Traffic_Global. The table will be visible and available to use for reporting.

 

07_CJC_6-1024x525.png

 

Client-Side Load

 

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:

 

  1. PROC CASUTIL
  2. DATA step
  3. PROC IMPORT

 

Examples: Client-Side Load Using PROC CASUTIL

 

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;
  • DATA= defines the library and table name to load into memory.
  • CASOUT= defines the name of the new in-memory table.
  • OUTCASLIB= defines the caslib the new in-memory table will be in.
  • PROMOTE ensures the table is global scope.

  08_CJC_7-1024x275.png

 

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;
  • FILE= defines the path, file name and file extension of the file to load into memory.

 

09_CJC_8-1024x212.png

 

Example: Client-Side Load Using the DATA Step

 

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;
  • Defining the casuser caslib ensures that ToyotaCars_CAS is an in-memory table.
  • (PROMOTE=YES) ensures the table is global scope.

 

10_CJC_9.png

  

10a_CJC_10.png

 

Example: Client-Side Load Using PROC IMPORT

 

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;
  • OPTIONS OBS= limits the number of observations that are imported.
  • DATAFILE= defines the path, file name and file extension of the file to load into memory.
  • OUT= defines the caslib and in-memory table name.

 

11_CJC_11.png

 

11a_CJC_18.png

 

Load Data to caslib Snippet

 

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

 

12_CJC_19-201x300.png

 

Viya Foundation

 

13_CJC_20-296x300.png

 

Cloud Analytic Services

 

14_CJC_21-300x295.png

 

Load Data to caslib

 

15_CJC_22.png

 

Modify the code in the snippet depending on the use-case.

 

16_CJC_23.png

 

Summary

 

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.

 

  • Server-Side Load: Use when the file is already in a caslib. This is the most efficient method and is performed using PROC CASUTIL.
  • Client-Side Load: Use when the file is on the Compute server and needs to be transferred to CAS. This can be done using PROC CASUTIL, the DATA step, or PROC IMPORT.

 

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?

 

Setting Up Your Environment in VFL

 

To follow along with this post in SAS Viya for Learners 4:

 

  1. Run the Generate SAS librefs for caslibs snippet to establish a CAS session and assign librefs to all available caslibs:
    • Navigate to Snippets > Viya Foundation > Cloud Analytic Services > Generate SAS librefs for caslibs.
    • Run the program.
    • Navigate to Libraries to view the available caslibs.

17_CJC_24.png

  1. Download the data from Air Traffic in Europe from 2016 to 2024.

18_CJC_25.png

  1. Upload the file airport_traffic_2024.csv to Explorer > Files > Home > casuser.

19_CJC_30-242x300.png

  1. Confirm the file is available in the casuser caslib using:
    • PROC CASUTIL INCASLIB="casuser";
         LIST FILES;
      QUIT;

20_CJC_27.png

 

  1. Create a new folder AirTraffic:
    • Navigate to Explorer> Files> Home> New> Folder and name it AirTraffic

21_CJC_28.png

    • Click the AirTraffic folder> Upload files> Add> select all CSV files previously downloaded> Open> Upload

22_CJC_29.png

 

For more on SAS Viya for Learners check out these posts:

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎03-06-2025 03:58 PM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

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.

Get started