Published on :
Data Access CREATION_INTERNE

Examples: Reading and Creating CAS Tables

This code is also available in: Deutsch Español Français
Awaiting validation
The document explains how to interact with CAS tables, load them from CSV files, and convert them back into SAS© datasets. Key points include: using the FILENAME URL access method to read data from a website, specifying a CAS engine libref for writing data as an in-memory CAS table, and saving a permanent copy of the in-memory CAS table using PROC CASUTIL. It also covers converting an in-memory CAS table into a SAS© dataset in a local SAS© library. Important notes on processing DATA steps in CAS are also provided, including the concept of default single-threaded execution for DATA steps without an input table, and how to force multi-threaded execution.
Data Analysis

Type : CREATION_INTERNE


The first example reads a CSV file from an external URL provided in the example, and the second example generates data internally using a DATA step.

1 Code Block
DATA STEP / PROC CASUTIL Data
Explanation :
In SAS, load the external comma-separated file using the INFILE statement. Specify a CAS engine libref for the output table. The TRUNCOVER option allows SAS to correctly read variable-length records. Variables without assigned values are set to missing. Specify the INPUT statement to list column names and read them as informats. Save a permanent copy of the in-memory CAS table.
Copied!
1filename names url
2 "http://support.sas.com/documentation/onlinedoc/viya/exampledatasets/names.csv";
3 
4DATA mycas.names;
5 INFILE names dsd truncover firstobs=2;
6 INPUT BRTH_YR :$10. GNDR :$10. ETHCTY :$10. NM :$10.
7 CNT :$10. RNK :$10.;
8RUN;
9 
10PROC CASUTIL incaslib='casuser';
11 save casdata='names' outcaslib='casuser' replace;
12 list;
13RUN;
2 Code Block
DATA STEP Data
Explanation :
Start a CAS session named Casauto and specify the personal caslib, Casuser, as the active caslib. Use the CAS LIBNAME statement to create a CAS engine libref. Create a CAS table named mycas.earnings to use for the example. Create a libref named mySAS to store the table as a SAS dataset. The libref mySAS represents the physical location where the dataset is stored. Read the mycas.earnings table and write it as a SAS dataset named mySAS.earnings.
Copied!
1cas casauto sessopts=(caslib='casuser');
2LIBNAME mycas cas;
3caslib _all_ assign;
4 
5DATA mycas.earnings;
6 Amount=1000;
7 Rate=.075/12;
8 DO month=1 to 12;
9 Earned +(amount+earned)*(rate);
10 END;
11RUN;
12PROC PRINT DATA=mycas.earnings;
13RUN;
14 
15LIBNAME mySAS "u/user/myfiles/";
16
17DATA mySAS.earnings;
18 SET mycas.earnings;
19RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Copyright © SAS Institute Inc. All Rights Reserved


Related Documentation : Data Access

Sujet / Mot-cléLien vers la ressource
DOC FedSQL en/sampleCode/FEDSQL9D66
Banner
Expert Advice
Expert
Michael
Responsable de l'infrastructure Viya.
« Navigating between the SAS Compute Server (traditional SAS) and the CAS Server (Cloud Analytic Services) requires a clear understanding of where your data "lives" and how it moves. The true power of SAS Viya lies in the ability to bridge these two environments seamlessly, but efficiency depends on how you handle memory and threading.

To verify where your DATA step is executing, check the SAS Log for the message: "The SAS System stopped processing this step because of errors" (which may indicate a CAS-incompatible function) or look for notes regarding "Running in CAS". If you don't see CAS-specific notes, your data is being pulled back to the local Compute Server, which can drastically slow down processing on large datasets. »