Many of the examples in the Python series of articles here use a CASTable object to invoke actions or apply DataFrame-like syntax to CAS tables. In those examples, the CASTable object is generally the result of an action that loads the CAS table from a data file or other data source. But what if you have a CAS table already loaded in a session and you want to create a new CASTable object that points to it?
The first thing you need is a connection to CAS.
In: import swat In: conn = swat.CAS(host, port, username, password)
We'll load a table of data here so we have something to work with. We'll also specify a table name and CASLib so they are easier to reference in the following step.
In: conn.read_csv('https://raw.githubusercontent.com/sassoftware/sas-viya-programming/master/data/class.csv', casout=dict(name='class', caslib='casuser')) Out: CASTable('class', caslib='CASUSER(kesmit)')
Using the tableinfo action, we can see that the table exists, however, we didn't store the output of the read_csv method, so we don't have a CASTable object pointing to it.
The solution is fairly simple, you use the CASTable method of the CAS connection object. You just pass it the name of the table and the name of the CASLib just as it is printed in In above.
In: cls = conn.CASTable('class', caslib='CASUSER') In: cls Out: CASTable('class', caslib='CASUSER')
We now have a CASTable object that we can use to interact with.
You can download the Jupyter notebook version of this article at https://github.com/sassoftware/sas-viya-programming/tree/master/communities.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.