0
0

More than 3 years have passed since last update.

CASTableのデータをエクスポートする

Posted at

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')

まとめ

エクスポートはファイルフォーマットの指定は不要で、ファイルの拡張子で自動的に判別されます。なお、ファイルはサーバ側に保存されるので、その点は注意してください。

SAS for Developers | SAS

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0