sas and python, sitting in a tree · sas have been busy in providing python wrappers and interfaces...

18
SAS and Python, Sitting in a Tree Cameron Lawson (Selerity)

Upload: others

Post on 13-Jul-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

SAS and Python, Sitting in a TreeCameron Lawson (Selerity)

Page 2: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Who Am I? SAS Consultant with Selerity, a silver SAS and AWS Partner.

Specialists in cloud based SAS delivery.

Close to 20yrs SAS programming, design and delivery experience.

Previously with Origin Energy and various Technology companies.

https://seleritysas.com

Page 3: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

About Python• Simple yet extremely powerful.

• Cross Platform

• Integrates with just about anything.

• Excellent analytic capability.

Page 4: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

SAS & Python = Awesome x 2. SAS have been busy in providing Python wrappers and Interfaces in

conjunction with other languages.

Python Library Suitable For

Python-SWAT SAS Viya™

SAS_kernel Integration with Jupyter Notebooks

saspy Interface for SAS 9x

Page 5: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

How Does it Help Me? You can now leverage the strengths

of other languages.

SAS and Viya is your analytics and data hub.

Does not replace SAS. It expands the scope of SAS.

Page 6: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Am I Running Python or SAS?

Python is the vehicle. SAS is the engine.

Python Programmers can use familiar programming patterns and tools.

SAS can augment Python, Python can augment SAS.

Viya allows Python to query Big Datasets efficiently.

Page 7: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Overview

Page 8: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

The Python-SWAT Library SAS Scripting Wrapper for Analytics Transfer

(SWAT)

Built on top of a popular Python programming interface called Pandas.

Two flavours, a binary and a REST Service interface. Binary library requires Linux and the numactl

package. REST client available for Windows, *nix, OSX etc. It’s open source! https://github.com/sassoftware/python-swat

Page 9: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Installation Installation via standard Python mechanismspip install https://github.com/sassoftware/python-

swat/releases/download/vX.X.X/python-swat-X.X.X-platform.tar.gz

Invocation is simple;import swat

cas = swat.CAS(host=‘’,port=‘’,method=‘cas’user=‘’,password=’’)

Load actionsets based on your licensingcas.loadactionset('simple')

Page 10: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Knowing What’s WhatDocumentation!

https://sassoftware.github.io/python-swat/index.html

## To see all available methods

cas.help()

## To see help for a specific actionset

cas.help(actionset='simple')

## Help for a specific Action

cas.help(action='regression')

Page 11: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Managing Datademo_csv = 'https://raw.githubusercontent.com/sassoftware/sas-viya-

programming/master/data/cars.csv’

ct = cas.read_csv(

demo_csv,

casout=dict(

name=’PYTHONCARS’,

caslib=’public’,

promote=True

)

)

sastable = cas.CASTable(name='SASCARS',caslib='public')

Page 12: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Viewing / Querying Data Many of the Pandas Data Frame methods are available

tbl.head(),tbl.tail(),tbl.fetch(to=10),tbl.describe()

Column Reduction tbl[‘Cylinders’,’Origin’]

Grouping tbl.groupby(['Origin', 'Cylinders']).summary(subset=['Min', 'Max'])

Sorting tbl.sort_values(['MSRP']).head()

Sub-setting tbl.query(‘Val > 0 and Val2==‘foo’).head()

Page 13: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

The Payoff

Page 14: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Viya-bot Use a Web Service created in

Python to be the back end of a Slack Bot.

Submit commands to Viya

Page 15: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Viya-bot Python is the middleware.

Runs CAS Actions and returns the results to Slack

Page 16: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

From Chatbot to Viya Data loaded to Viya and now

available to any SAS application or other interface.

Page 17: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Exploit in SAS Use the data for VA, Visual

Statistics, SAS Studio etc.

Page 18: SAS and Python, Sitting in a Tree · SAS have been busy in providing Python wrappers and Interfaces in conjunction with other languages. Python Library SuitableFor Python-SWAT SAS

Copyright © 2017 SelerityTM - a trademark of Scorpio Software Services Pty Ltd.

Further Info SAS Developers

https://developer.sas.com/guides/python.html

The Source Code https://github.com/sassoftware/python-swat/

SAS Viya The Python Perspective https://github.com/sassoftware/sas-viya-the-python-

perspective

Selerity Blog https://seleritysas.com/blog