The data used for the demonstration ('COLUMNSAMPLE' table) is created directly in the script via DATALINES statements, making it an internal source. However, the script is configured to connect to an external data source (ODBC) via the `addCaslib` action, but no data is actually read from this external source for the `columnInfo` examples.
1 Code Block
Macro Variables / CAS Setup
Explanation : This block initializes macro variables (`srctype`, `cas_session`, `caslib_alias`, `username`, `password`, `database`, `schema`, `CONNOPTS`) used to configure the connection to the data source and the CAS session. The `cas &cas_session;` line establishes a new CAS session named 'mysess', essential for all subsequent CAS operations.
Copied!
/* Specify the DBMS engine, for example: ODBC */
%let srctype=odbc;
%let cas_session = mysess;
%let caslib_alias = datalib;
/*Specify connection parameters within a string
Edit the below variables with the required DBMS-specific conection options
Also, specify such variables within the CONNOPS string, as this will be used for the other sample programs
Most datasources will require username, password, database, and schema/server
Please refer to the connopts.xlsx file for specific connection requirements for each DBMS engine
BigQuery: requires protject and cred_path parameters
Hadoop: requires hadoopJarPath, hadoopConfigDir, and dtm parameters
Impala: requires port and conopts parameters
JDBC: requires url, class, and classpath parameters
Salesforce: requires authendpoint and catalog parameters
SAP Hana: requires instance and tabletype parameters
Teradata: requires dataTransferMode parameter
Oracle, Netezza, and MSSWL require catalog parameter
*/
%let username = ???????;
%let password = ???????;
%let database = ???????;
%let schema = ???????;
%let CONNOPTS=%str(user=???????
pwd=???????
dsn=???????);
/* Connect to CAS using cashost and casport, optional in SAS Studio */
/* options cashost="????????" casport=????; */
/* Create a CAS Session */
cas &cas_session;
1
/* Specify the DBMS engine, for example: ODBC */
2
%let srctype=odbc;
3
4
%let cas_session = mysess;
5
%let caslib_alias = datalib;
6
7
8
/*Specify connection parameters within a string
9
10
Edit the below variables with the required DBMS-specific conection options
11
Also, specify such variables within the CONNOPS string, as this will be used for the other sample programs
12
13
Most datasources will require username, password, database, and schema/server
14
Please refer to the connopts.xlsx file for specific connection requirements for each DBMS engine
15
16
BigQuery: requires protject and cred_path parameters
17
Hadoop: requires hadoopJarPath, hadoopConfigDir, and dtm parameters
18
Impala: requires port and conopts parameters
19
JDBC: requires url, class, and classpath parameters
20
Salesforce: requires authendpoint and catalog parameters
21
SAP Hana: requires instance and tabletype parameters
22
Teradata: requires dataTransferMode parameter
23
Oracle, Netezza, and MSSWL require catalog parameter
24
25
*/
26
27
%let username = ???????;
28
%let password = ???????;
29
%let database = ???????;
30
%let schema = ???????;
31
32
%let CONNOPTS=%str(user=???????
33
pwd=???????
34
dsn=???????);
35
36
/* Connect to CAS using cashost and casport, optional in SAS Studio */
37
/* options cashost="????????" casport=????; */
38
39
40
/* Create a CAS Session */
41
cas &cas_session;
2 Code Block
PROC CAS (addCaslib action)
Explanation : This block uses the PROC CAS procedure and its `addCaslib` action to define a new CASLIB. This CASLIB, named 'datalib', is configured to connect to an ODBC data source using the parameters specified by the macro variables (username, password, database, etc.). This allows CAS to access tables from the external database via this CASLIB.
Explanation : This block defines a LIBNAME 'caslib' to refer to the previously created CASLIB (`datalib`) and associates it with the active CAS session. Then, a DATA STEP is used to create a new in-memory table called 'COLUMNSAMPLE' within this CASLIB. The data for this table is provided directly via `datalines` statements, simulating a table to be analyzed.
Copied!
/* Create in-memory tables in CAS using CAS Libname engine */
libname caslib cas sessref=&cas_session tag="";
data caslib.COLUMNSAMPLE;
input FLIGHT $3. +5 DATES $7. +3 DEPART $5. +2 ORIG $3.
+3 DEST $3. +7 MILES +6 BOARDED +6 CAPACITY;
datalines;
114 01MAR98 7:10 LGA LAX 2475 172 210
202 01MAR98 10:43 LGA ORD 740 151 210
219 01MAR98 9:31 LGA LON 3442 198 250
622 01MAR98 12:19 LGA FRA 3857 207 250
132 01MAR98 15:35 LGA YYZ 366 115 178
271 01MAR98 13:17 LGA PAR 3635 138 250
302 01MAR98 20:22 LGA WAS 229 105 180
114 02MAR98 7:10 LGA LAX 2475 119 210
202 02MAR98 10:43 LGA ORD 740 120 210
219 02MAR98 9:31 LGA LON 3442 147 250
622 02MAR98 12:19 LGA FRA 3857 176 250
132 02MAR98 15:35 LGA YYZ 366 106 178
;
run;
1
/* Create in-memory tables in CAS using CAS Libname engine */
Explanation : This example uses the CAS `table.columnInfo` action to retrieve detailed information about all columns of the 'COLUMNSAMPLE' table residing in the 'datalib' CASLIB. This action provides metadata such as column names, type, length, etc.
Explanation : Similar to the previous block, but this example demonstrates how to limit the returned information to a subset of specific columns ('FLIGHT', 'DATES', 'BOARDED', 'CAPACITY') using the `vars` parameter of the `table.columnInfo` action. This is useful for targeted analyses.
Copied!
/*Proc cas columninfo action with specified vars variable */
proc cas;
table.columnInfo /
table={name="COLUMNSAMPLE",
caslib = "&caslib_alias"
vars={"FLIGHT", "DATES", "BOARDED", "CAPACITY"}};
run;
quit;
1
/*Proc cas columninfo action with specified vars variable */
2
PROC CAS;
3
TABLE.columnInfo /
4
TABLE={name="COLUMNSAMPLE",
5
caslib = "&caslib_alias"
6
vars={"FLIGHT", "DATES", "BOARDED", "CAPACITY"}};
7
RUN;
8
QUIT;
6 Code Block
PROC CAS (table.columnInfo action)
Explanation : This example presents an alternative method for specifying columns of interest. Instead of using the `vars` parameter within the `table` option, it uses the `inputs` parameter directly under the `table.columnInfo` action, passing it a list of dictionaries where each dictionary specifies the name of a variable ('FLIGHT', 'BOARDED').
Copied!
/*Proc cas columninfo action alternative method of specifying variables to display*/
proc cas;
table.columnInfo /
inputs = {{name="FLIGHT"},{name="BOARDED"}}
table={name = "COLUMNSAMPLE",
caslib = "&caslib_alias"};
run;
quit;
1
/*Proc cas columninfo action alternative method of specifying variables to display*/
2
PROC CAS;
3
TABLE.columnInfo /
4
inputs = {{name="FLIGHT"},{name="BOARDED"}}
5
TABLE={name = "COLUMNSAMPLE",
6
caslib = "&caslib_alias"};
7
RUN;
8
QUIT;
7 Code Block
CAS Session Termination
Explanation : This command terminates the previously established CAS session, thereby releasing associated resources. It is good practice to always terminate CAS sessions after use.
Copied!
/* Remove CAS session */
cas &cas_session. terminate;
1
/* Remove CAS
2
session */
3
cas &cas_session. terminate;
4
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.