SAS Accessing Data

Starting a CAS Session

Before you can begin accessing your data, you must have an active CAS session.

The following example starts a CAS session. The CAS statement is used to connect to the Cloud Analytic Services.

cas mySession;

The CAS session name is mySession. If you do not specify a session name, the default session name is Casauto.

The following is printed to the log.


NOTE: The session MYSESSION connected successfully to Cloud Analytic Services 
       using port 5570. The UUID is 650af61d-4576-da4b-a4a5-9069737d5897. 
      The user is sasdemo and the active caslib is CASUSER(sasdemo).
NOTE: The SAS option SESSREF was updated with the value MYSESSION.
NOTE: The SAS macro _SESSREF_ was updated with the value MYSESSION.
NOTE: The session is using 0 workers.

Adding a Caslib

Note: This example assumes that you have permissions to add a Caslib. For more information, see CASLIB Statement in SAS Cloud Analytic Services: User’s Guide and Adjust Caslib Management Privileges in SAS Environment Manager: User’s Guide.

The following example adds a caslib using the CASLIB Statement in SAS Cloud Analytic Services: User’s Guide CAS LIBNAME statement. The LIBNAME statement associates the libref with the caslib by using the CAS engine.

caslib myCaslib datasource=(srctype="path") path="/data/path/" sessref=mysession subdirs; libname myCaslib cas;


NOTE: Libref MYCASLIB was successfully assigned as follows: 
      Engine:        CAS 
      Physical Name: 650af61d-4576-da4b-a4a5-9069737d5897

Ways to Access Data

You can import your data to the CAS server or the SAS Compute Server by using CAS actions, the CAS procedure, or the SAS DATA step. These examples demonstrate different ways to import data.

Loading a CSV File by Using the CASUTIL Procedure

This example loads a CSV file to the CAS server by using the CASUTIL procedure.

proc casutil; /*1*/ load file="/data/path/creditscores.csv" /*2*/ importoptions= /*3*/ (filetype="csv" getnames="true") outcaslib="mycaslib" casout="creditscores" /*4*/ replace; /*5*/ quit;

  1. The CASUTIL procedure manages tables and files in SAS Cloud Analytic Services.
  2. The LOAD statement reads the Creditscores CSV file and loads it to the CAS server. The FILE= argument specifies Creditscores as the external CSV file, which is accessible to the CAS server.
  3. The IMPORTOPTIONS= parameter specifies the file format and options. Specify CSV as the file format. The GETNAMES= parameter specifies the use of the first row in the CSV file as the variable name.
  4. The OUTCASLIB= parameter specifies MyCaslib as the caslib to use for the in-memory table, Creditscores. The CASOUT= parameter specifies Creditscores as the name for the in-memory table.
  5. The REPLACE parameter replaces any existing in-memory table that is named CreditScores.

The following notes are printed to the log:


NOTE: Cloud Analytic Services made the uploaded file available as table CREDITSCORES in caslib CASUSER(sasdemo).
NOTE: The table CREDITSCORES has been created in caslib MYCASLIB(sasdemo) from binary data uploaded to Cloud Analytic Services.

TIP The LOAD statement in PROC CASUTIL is the recommended way to load files to in-memory tables. For more information about loading client-side data source files, see CASUTIL Procedure in SAS Cloud Analytic Services: User’s Guide.

Downloading and Loading a File to the CAS Server

The following example downloads a file from the SAS website, and then loads the file to the CAS server. The HTTP procedure downloads the CreditScores data set to a local temporary file. The UPLOAD statement uploads the table to the CAS server. The file is then received by CAS and stored as a temporary file until the file is loaded as an in-memory table. After the table is loaded, the file is removed.

filename creditscores temp; /*1*/ proc http /*2*/ url=' onlinedoc/viya/exampledatasets/creditscores.csv' out=creditscores; run; proc cas; upload /*3*/ path="%sysfunc(pathname(creditscores))" casOut={caslib="mycaslib", name="creditscores"} importOptions="csv"; run; table.tableInfo / /*4*/ caslib="mycaslib", table="creditscores"; quit; filename creditscores clear; /*5*/

  1. The FILENAME statement creates the fileref Creditscores for the SAS temporary folder so that the Creditscores.csv file can be stored in this folder..
  2. The HTTP procedure creates a GET request for the Creditscores.csv file.
  3. The UPLOAD statement uploads the file Creditscores.csv to CAS as the in-memory table Creditscores. The PATH= argument uses the %SYSFUNC function to specify the path to the input file. The CASOUT= option specifies that the in-memory table name is Creditscores and that it is stored in MyCaslib. The IMPORTOPTIONS= option specifies the file type of the input file.
  4. The tableInfo action displays information about the in-memory table Creditscores. Although this step is not necessary, it is recommended to check the contents of the table after it has been loaded to the CAS server.
  5. The FILENAME statement clears the Creditscores fileref.


NOTE: Cloud Analytic Services made the uploaded file available as table CREDITSCORES in caslib MYCASLIB(sasdemo).
NOTE: The table CREDITSCORES has been created in caslib MYCASLIB(sasdemo) from binary data uploaded to Cloud Analytic Services.

tableInfo Action Results