Published on :
ETL CREATION_INTERNE_ET_EXTERNE

Examples: Read and Create CAS Tables

This code is also available in: Deutsch Español Français
Awaiting validation
The first example illustrates the process of reading a remote CSV file (provided via a URL) and loading it into an in-memory CAS table. It uses the FILENAME URL access method and a DATA step executed on the SAS© Compute Server to structure the data. Then, the CASUTIL procedure is employed to save a permanent copy of the in-memory CAS table. The second example demonstrates how a DATA step can be used to convert an existing in-memory CAS table into a classic SAS© dataset, stored in a user-defined SAS© library. These examples highlight the interoperability between CAS sessions, CAS libraries, and SAS© libraries for data management.
Data Analysis

Type : CREATION_INTERNE_ET_EXTERNE


The first example reads raw data from an external CSV file accessible via a URL. The second example generates its own data internally via a DATA step.

1 Code Block
DATA STEP / PROC CASUTIL
Explanation :
This code loads a CSV file from a URL into a CAS table. The 'FILENAME' statement defines the URL. The 'DATA step' reads the file, specifying a CAS libref (mycas.names) for the output, indicating that the data is loaded into CAS memory. 'INFILE' handles the CSV format, and 'INPUT' assigns the variables. Finally, 'PROC CASUTIL' is used to permanently save the in-memory CAS table and list it.
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 :
This example converts a CAS table to a SAS dataset. First, a CAS session is started and a CAS libref (mycas) is created. A first DATA step generates a CAS table named 'mycas.earnings' with calculated data. Then, a libname is defined for a local SAS library ('mySAS'). Finally, a second DATA step reads the CAS table 'mycas.earnings' and saves it as a SAS dataset '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=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