0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SAS ViyaのFetchオブジェクトのパラメータ操作について

Posted at

SAS ViyaはAIプラットフォームです。PythonやJava、Rなどの言語を通して利用できます。そのSAS Viyaの中で使われているのがCASTableというテーブルオブジェクトです(CASはCloud Analytic Servicesの略です)。CASTableからデータを取得する際のパラメータをネストして与える方法について紹介します。

SAS Viyaに接続する

まずはSAS Viyaに接続します。

from swat import *

cashost='localhost'
casport=5570
useremail='dev@sas.com'
userpassword='password'
casauth='~/.authinfo'
conn = CAS(cashost, casport, useremail, userpassword, caslib="casuser")

データをアップロードする

CSVファイルのデータをアップロードします。今回は有名なIRISのデータです。

out = conn.upload('./iris.csv')

Fetchオブジェクトを取得する

Fetchオブジェクトをconnから取得します。初期値としてテーブルなどを指定できます。

fa = conn.Fetch(to=5, table=dict(name='IRIS', caslib='casuser'))

パラメータの取得

パラメータを取得する際には get_param を使います。

fa.get_param('to')

# -> 5

複数の引数を指定することで複数の値を取得できます。

fa.get_params('to', 'table.name')

# -> {'table.name': 'IRIS', 'to': 5}

パラメータの削除

パラメータの削除は del_params を使います。

fa.del_params('to', 'table.caslib')

パラメータの確認

パラメータの存在確認は has_param を使います。

fa.has_param('table.caslib')

# -> False

複数指定した場合は、すべての項目がある場合のみTrueが返ってきます。

fa.has_param('table.name', 'to')

# -> False

プロパティを使ったアクセス

プロパティを指定して値を取得することもできます。

fa.table.name

# -> 'IRIS'

同じようにデータの削除もできます。

fa.table

# -> {'caslib': 'casuser', 'name': 'IRIS'}

データを削除します。

del fa.table.caslib

確認します。

fa.table

# -> {'name': 'IRIS'}

まとめ

SAS ViyaのFetchオブジェクトは柔軟にデータ指定ができます。プログラマブルに条件を変更するのも簡単でしょう。ぜひお試しください。

Python Programming for SAS Viya | 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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?