SAS ViyaはAIプラットフォームです。PythonやJava、Rなどの言語を通して利用できます。そのSAS Viyaの中で使われているのがCASTableというテーブルオブジェクトです(CASはCloud Analytic Servicesの略です)。今回はCASTableのデータをエクスポートする方法を紹介します。
データベースからテーブルを取得する
まずはSAS Viyaに接続します。
import swat
conn = swat.CAS('server-name.mycompany.com', 5570, 'username', 'password')
次にCASTableを取得します。今回はIRISデータのCSVを利用します。
tbl = conn.loadtable('data/iris.csv', caslib='casuser').casTable
エクスポートする
例えばCSVでエクスポートする場合は次のように行います。
tbl.save(name='data/irisout.csv', caslib='casuser')
すでにファイルがある場合はメッセージが出ます。
The file /u/username/data/irisout.csv already exists. Specify the replace option to overwrite an existing file.
The action stopped due to errors.
SASのファイルフォーマットSASHDATで出力する場合は次のように行います。
tbl.save(name='data/irisout.sashdat', caslib='casuser')
まとめ
エクスポートはファイルフォーマットの指定は不要で、ファイルの拡張子で自動的に判別されます。なお、ファイルはサーバ側に保存されるので、その点は注意してください。