LoginSignup
0
0

More than 3 years have passed since last update.

SAS ViyaでExcelのテーブルをデータソースにする

Posted at

SAS ViyaはAIプラットフォームです。データソースは様々なものが指定できますが、今回はExcelファイルをターゲットにする方法を紹介します。

ライブラリの読み込み

ライブラリを読み込みます。

from swat.cas import datamsghandlers as dmh

Excelファイルを指定する

次にExcelファイルを指定します。トライアル環境の場合はURL指定ができませんので、Excelファイルをアップロードした上で指定してください。今回は2015 Crop Year Secretarial Disaster Designationsを使っています。

exceldmh = dmh.Excel('./disaster_cty_list_ytd_15.xls')

データ型などは自動的に判別されます。

exceldmh.args.addtable
{'datamsghandler': <swat.cas.datamsghandlers.Excel at 0x7f47ab9b95c0>,
 'reclen': 320,
 'vars': [{'length': 8,
   'name': 'FIPS',
   'offset': 0,
   'rtype': 'NUMERIC',
   'type': 'SAS'},
  {'length': 16,
   'name': 'County',
   'offset': 8,
   'rtype': 'CHAR',
   'type': 'VARCHAR'},
  {'length': 16,
   'name': 'State',
   'offset': 24,
   'rtype': 'CHAR',
   'type': 'VARCHAR'}
   :
}

Viya用のテーブルにする

まずSAS Viyaのオブジェクトを作ります。

from swat import *

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

そしてテーブルを取り込みます。

out = conn.addtable(table='crops', caslib='casuser', **exceldmh.args.addtable)

テーブルの構造を確認する

テーブル構造を確認します。

out.casTable.columninfo(table=dict(name='crops', caslib='casuser'))
Column ID Type RawLength FormattedLength Format NFL NFD
0 FIPS 1 double 8 12 0
1 County 2 varchar 15 15 0
: : : : : : : :
33 Unnamed: 33 34 varchar 101 101 0
34 Unnamed: 34 35 double 8 12 0

このように文字型、数字型を自動的に判別されていれば大丈夫です。

まとめ

他にもデータソースはHTMLファイルやCSVファイルなども利用できます。多彩なソースを取り込んで分析できますので、ぜひトライアルをお試しください。

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