API Reference

saspy.isnotebook()

SAS Session Object

class saspy.SASsession(**kwargs) → saspy.sasbase.SASsession

Bases: object

Overview

The SASsession object is the main object to instantiate and provides access to the rest of the functionality. Most of these parameters will be configured in the sascfg.py configuration file.

Common parms for all access methods are:

Parameters:
  • cfgname – value in SAS_config_names List of the sascfg.py file
  • kernel – None - internal use when running the SAS_kernel notebook
  • results – Type of tabular results to return. default is ‘Pandas’, other options are ‘HTML or ‘TEXT’
Returns:

‘SASsession’

Return type:

‘SASsession’

And each access method has its own set of parameters.

STDIO

Parameters:
  • saspath – overrides saspath Dict entry of cfgname in sascfg.py file
  • options – overrides options Dict entry of cfgname in sascfg.py file
  • encoding – This is the python encoding value that matches the SAS session encoding

STDIO over SSH

and for running STDIO over passwordless ssh, add these required parameters

Parameters:
  • ssh – full path of the ssh command; /usr/bin/ssh for instance
  • host – host name of the remote machine

IOM

and for the IOM IO module to connect to SAS9 via Java IOM

Parameters:
  • java – the path to the java executable to use
  • iomhost – for remote IOM case, not local Windows] the resolvable host name, or ip to the IOM server to connect to
  • iomport – for remote IOM case, not local Windows] the port IOM is listening on
  • omruser – user id for remote IOM access
  • omrpw – pw for user for remote IOM access
  • encoding – This is the python encoding value that matches the SAS session encoding of the IOM server you are connecting to
  • classpath – classpath to IOM client jars and saspyiom client jar.
dataframe2sasdata(df: pandas.core.frame.DataFrame, table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) → saspy.sasbase.SASdata

This method imports a Pandas Data Frame to a SAS Data Set, returning the SASdata object for the new Data Set.

Parameters:
  • df – Pandas Data Frame to import to a SAS Data Set
  • table – the name of the SAS Data Set to create
  • libref – the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned
  • results – format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives
Returns:

SASdata object

datasets(libref: str = '') → str

This method is used to query a libref. The results show information about the libref including members.

Parameters:libref – the libref to query
Returns:
df2sd(df: pandas.core.frame.DataFrame, table: str = '_df', libref: str = '', results: str = '', keep_outer_quotes: bool = False) → saspy.sasbase.SASdata

This is an alias for ‘dataframe2sasdata’. Why type all that?

Parameters:
  • dfpandas.DataFrame Pandas Data Frame to import to a SAS Data Set
  • table – the name of the SAS Data Set to create
  • libref – the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned
  • results – format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives
Returns:

SASdata object

disconnect()

This method disconnects an IOM session to allow for reconnecting when switching networks See the Advanced topics section of the doc for details

exist(table: str, libref: str = '') → bool

Does the SAS data set currently exist

Parameters:
  • table – the name of the SAS Data Set
  • libref – the libref for the Data Set, defaults to WORK, or USER if assigned
Returns:

Boolean True it the Data Set exists and False if it does not

Return type:

bool

read_csv(file: str, table: str = '_csv', libref: str = '', results: str = '', opts: dict = {}) → saspy.sasbase.SASdata
Parameters:
  • file – either the OS filesystem path of the file, or HTTP://... for a url accessible file
  • table – the name of the SAS Data Set to create
  • libref – the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned
  • results – format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives
  • opts – a dictionary containing any of the following Proc Import options(datarow, delimiter, getnames, guessingrows)
Returns:

SASdata object

sasdata(table: str, libref: str = '', results: str = '', dsopts: dict = {}) → saspy.sasbase.SASdata

Method to define an existing SAS dataset so that it can be accessed via SASPy

Parameters:
  • table – the name of the SAS Data Set
  • libref – the libref for the Data Set, defaults to WORK, or USER if assigned
  • results – format of results, SASsession.results is default, Pandas, HTML and TEXT are the valid options
  • dsopts

    a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs):

    • where is a string
    • keep are strings or list of strings.
    • drop are strings or list of strings.
    • obs is a numbers - either string or int
    • first obs is a numbers - either string or int
    {'where'    : 'msrp < 20000 and make = "Ford"'
     'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
     'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
     'obs'      :  10
     'firstobs' : '12'
    }
    
Returns:

SASdata object

sasdata2dataframe(table: str, libref: str = '', dsopts: dict = {}, method: str = 'MEMORY', **kwargs) → pandas.core.frame.DataFrame

This method exports the SAS Data Set to a Pandas Data Frame, returning the Data Frame object. SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame

Parameters:
  • table – the name of the SAS Data Set you want to export to a Pandas Data Frame
  • libref – the libref for the SAS Data Set.
  • dsopts

    a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs):

    • where is a string
    • keep are strings or list of strings.
    • drop are strings or list of strings.
    • obs is a numbers - either string or int
    • first obs is a numbers - either string or int
    {'where'    : 'msrp < 20000 and make = "Ford"'
     'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
     'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
     'obs'      :  10
     'firstobs' : '12'
    }
    
  • method – defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data
  • kwargs – dictionary
Returns:

Pandas data frame

sasets() → saspy.sasets.SASets

This methods creates a SASets object which you can use to run various analytics. See the sasets.py module. :return: sasets object

saslib(libref: str, engine: str = ' ', path: str = '', options: str = ' ', prompt: dict = []) → str
Parameters:
  • libref – the libref to be assigned
  • engine – the engine name used to access the SAS Library (engine defaults to BASE, per SAS)
  • path – path to the library (for engines that take a path parameter)
  • options – other engine or engine supervisor options
Returns:

SAS log

saslog() → str

This method is used to get the current, full contents of the SASLOG

Returns:SAS log
Return type:str
sasml() → saspy.sasml.SASml

This methods creates a SASML object which you can use to run various analytics. See the sasml.py module.

Returns:sasml object
sasqc() → saspy.sasqc.SASqc

This methods creates a SASqc object which you can use to run various analytics. See the sasqc.py module.

Returns:sasqc object
sasstat() → saspy.sasstat.SASstat

This methods creates a SASstat object which you can use to run various analytics. See the sasstat.py module.

Returns:sasstat object
sasutil() → saspy.sasutil.SASutil

This methods creates a SASutil object which you can use to run various analytics. See the sasutil.py module.

Returns:sasutil object
sd2df(table: str, libref: str = '', dsopts: dict = {}, method: str = 'MEMORY', **kwargs) → pandas.core.frame.DataFrame

This is an alias for ‘sasdata2dataframe’. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame

Parameters:
  • table – the name of the SAS Data Set you want to export to a Pandas Data Frame
  • libref – the libref for the SAS Data Set.
  • dsopts

    a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs):

    • where is a string
    • keep are strings or list of strings.
    • drop are strings or list of strings.
    • obs is a numbers - either string or int
    • first obs is a numbers - either string or int
    {'where'    : 'msrp < 20000 and make = "Ford"'
     'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
     'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
     'obs'      :  10
     'firstobs' : '12'
    }
    
  • method – defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data
  • kwargs – dictionary
Returns:

Pandas data frame

sd2df_CSV(table: str, libref: str = '', dsopts: dict = {}, tempfile: str = None, tempkeep: bool = False, **kwargs) → pandas.core.frame.DataFrame

This is an alias for ‘sasdata2dataframe’ specifying method=’CSV’. Why type all that? SASdata object that refers to the Sas Data Set you want to export to a Pandas Data Frame

Parameters:
  • table – the name of the SAS Data Set you want to export to a Pandas Data Frame
  • libref – the libref for the SAS Data Set.
  • dsopts

    a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs):

    • where is a string
    • keep are strings or list of strings.
    • drop are strings or list of strings.
    • obs is a numbers - either string or int
    • first obs is a numbers - either string or int
    {'where'    : 'msrp < 20000 and make = "Ford"'
     'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
     'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
     'obs'      :  10
     'firstobs' : '12'
    }
    
  • tempfile – [optional] an OS path for a file to use for the local CSV file; default it a temporary file that’s cleaned up
  • tempkeep – if you specify your own file to use with tempfile=, this controls whether it’s cleaned up after using it
  • kwargs – dictionary
Returns:

Pandas data frame

set_batch(batch: bool) → bool

This method sets the batch attribute for the SASsession object; it stays in effect until changed. For methods that just display results like SASdata object methods (head, tail, hist, series, etc.) and SASresult object results, you can set ‘batch’ to true to get the results back directly so you can write them to files or whatever you want to do with them.

This is intended for use in python batch scripts so you can still get ODS XML5 results and save them to files, which you couldn’t otherwise do for these methods. When running interactively, the expectation is that you want to have the results directly rendered, but you can run this way too; get the objects display them yourself and/or write them to somewhere.

When set_batch ==True, you get the same dictionary returned as from the SASsession.submit() method.

Parameters:batch – bool
Return type:bool
Returns:True = return dict([LOG, LST]. False = display LST to screen.
set_results(results: str) → str

This method set the results attribute for the SASsession object; it stays in effect till changed

Parameters:results – set the default result type for this SASdata object. 'Pandas' or 'HTML' or 'TEXT'.
Returns:string of the return type
Return type:str
submit(code: str, results: str = '', prompt: dict = []) → dict

This method is used to submit any SAS code. It returns the Log and Listing as a python dictionary.

  • code - the SAS statements you want to execute

  • results - format of results, HTLML and TEXT is the alternative

  • prompt - dict of names:flags to prompt for; create macro variables (used in submitted code), then keep or delete

    the keys which are the names of the macro variables. The boolean flag is to either hide what you type and delete the macros, or show what you type and keep the macros (they will still be available later).

    for example (what you type for pw will not be displayed, user and dsname will):

    results_dict = sas.submit(
                 """
                 libname tera teradata server=teracop1 user=&user pw=&pw;
                 proc print data=tera.&dsname (obs=10); run;
                 """ ,
                 prompt = {'user': False, 'pw': True, 'dsname': False}
                 )
    

    Returns - a Dict containing two keys:values, [LOG, LST]. LOG is text and LST is ‘results’ (HTML or TEXT)

NOTE: to view HTML results in the ipykernel, issue: from IPython.display import HTML and use HTML() instead of print()

i.e,: results = sas.submit(“data a; x=1; run; proc print;run’)
print(results[‘LOG’]) HTML(results[‘LST’])
symget(name)
Parameters:name

name of the macro varable to set:

  • name is a character
symput(name, value)
Parameters:
  • name – name of the macro varable to set:
  • value

    python variable to use for the value to assign to the macro variable:

    • name is a character
    • value is a variable that can be resolved to a string
teach_me_SAS(nosub: bool)
nosub - bool. True means don’t submit the code, print it out so I can see what the SAS code would be.
False means run normally - submit the code.
write_csv(file: str, table: str, libref: str = '', dsopts: dict = {}, opts: dict = {}) → str
Parameters:
  • file – the OS filesystem path of the file to be created (exported from the SAS Data Set)
  • table – the name of the SAS Data Set you want to export to a CSV file
  • libref – the libref for the SAS Data Set being created. Defaults to WORK, or USER if assigned
  • dsopts – a dictionary containing any of the following SAS data set options(where, drop, keep, obs, firstobs)
  • opts

    a dictionary containing any of the following Proc Export options(delimiter, putnames)

    • where is a string
    • keep are strings or list of strings.
    • drop are strings or list of strings.
    • obs is a numbers - either string or int
    • first obs is a numbers - either string or int
    {'where'    : 'msrp < 20000 and make = "Ford"'
     'keep'     : 'msrp enginesize Cylinders Horsepower Weight'
     'drop'     : ['msrp', 'enginesize', 'Cylinders', 'Horsepower', 'Weight']
     'obs'      :  10
     'firstobs' : '12'
    }
    
Returns:

SAS log

SAS Data Object

class saspy.SASdata(sassession, libref, table, results='', dsopts={})

Bases: object

assessModel(target: str, prediction: str, nominal: bool = True, event: str = '', **kwargs)

This method will calculate assessment measures using the SAS AA_Model_Eval Macro used for SAS Enterprise Miner. Not all datasets can be assessed. This is designed for scored data that includes a target and prediction columns TODO: add code example of build, score, and then assess

Parameters:
  • target – string that represents the target variable in the data
  • prediction – string that represents the numeric prediction column in the data. For nominal targets this should a probability between (0,1).
  • nominal – boolean to indicate if the Target Variable is nominal because the assessment measures are different.
  • event – string which indicates which value of the nominal target variable is the event vs non-event
  • kwargs
Returns:

SAS result object

bar(var: str, title: str = '', label: str = '') → object

This method requires a character column (use the contents method to see column types) and generates a bar chart.

Parameters:
  • var – the CHAR variable (column) you want to plot
  • title – an optional title for the chart
  • label – LegendLABEL= value for sgplot
Returns:

graphic plot

columnInfo()

display metadata about the table, size, number of rows, columns and their data type

contents()

display metadata about the table. size, number of rows, columns and their data type ...

Returns:output
describe()

display descriptive statistics for the table; summary statistics.

Returns:
head(obs=5)

display the first n rows of a table

Parameters:obs – the number of rows of the table that you want to display. The default is 5
Returns:
heatmap(x: str, y: str, options: str = '', title: str = '', label: str = '') → object

Documentation link: http://support.sas.com/documentation/cdl/en/grstatproc/67909/HTML/default/viewer.htm#n0w12m4cn1j5c6n12ak64u1rys4w.htm

Parameters:
  • x – x variable
  • y – y variable
  • options – display options (string)
  • title – graph title
  • label
Returns:

hist(var: str, title: str = '', label: str = '') → object

This method requires a numeric column (use the contents method to see column types) and generates a histogram.

Parameters:
  • var – the NUMERIC variable (column) you want to plot
  • title – an optional Title for the chart
  • label – LegendLABEL= value for sgplot
Returns:

impute()

Imputes missing values for a SASdata object.

Parameters:
  • vars – a dictionary in the form of {‘varname’:’impute type’} or {‘impute type’:’[var1, var2]’}
  • replace
  • prefix
  • out
Returns:

info()

Display the column info on a SAS data object

Returns:Pandas data frame
means()

display descriptive statistics for the table; summary statistics. This is an alias for ‘describe’

Returns:
partition(var: str = '', fraction: float = 0.7, seed: int = 9878, kfold: int = 1, out: typing.Union[saspy.sasbase.SASdata, NoneType] = None, singleOut: bool = True) → object

Partition a sas data object using SRS sampling or if a variable is specified then stratifying with respect to that variable

Parameters:
  • var – variable(s) for stratification. If multiple then space delimited list
  • fraction – fraction to split
  • seed – random seed
  • kfold – number of k folds
  • out – the SAS data object
  • singleOut – boolean to return single table or seperate tables
Returns:

Tuples or SAS data object

scatter(x: str, y: list, title: str = '') → object

This method plots a scatter of x,y coordinates. You can provide a list of y columns for multiple line plots.

Parameters:
  • x – the x axis variable; generally a time or continuous variable.
  • y – the y axis variable(s), you can specify a single column or a list of columns
  • title – an optional Title for the chart
Returns:

graph object

score(file: str = '', code: str = '', out: typing.Union[saspy.sasbase.SASdata, NoneType] = None) → saspy.sasbase.SASdata

This method is meant to update a SAS Data object with a model score file.

Parameters:
  • file – a file reference to the SAS score code
  • code – a string of the valid SAS score code
  • out – Where to the write the file. Defaults to update in place
Returns:

The Scored SAS Data object.

series(x: str, y: list, title: str = '') → object

This method plots a series of x,y coordinates. You can provide a list of y columns for multiple line plots.

Parameters:
  • x – the x axis variable; generally a time or continuous variable.
  • y – the y axis variable(s), you can specify a single column or a list of columns
  • title – an optional Title for the chart
Returns:

graph object

set_results(results: str)

This method set the results attribute for the SASdata object; it stays in effect till changed results - set the default result type for this SASdata object. ‘Pandas’ or ‘HTML’ or ‘TEXT’.

Parameters:results – format of results, SASsession.results is default, PANDAS, HTML or TEXT are the alternatives
Returns:None
sort(by: str, out: object = '', **kwargs) → saspy.sasbase.SASdata

Sort the SAS Data Set

Parameters:
  • by – REQUIRED variable to sort by (BY <DESCENDING> variable-1 <<DESCENDING> variable-2 ...>;)
  • out – OPTIONAL takes either a string ‘libref.table’ or ‘table’ which will go to WORK or USER if assigned or a sas data object’’ will sort in place if allowed
  • kwargs
Returns:

SASdata object if out= not specified, or a new SASdata object for out= when specified

Example:
  1. wkcars.sort(‘type’)
  2. wkcars2 = sas.sasdata(‘cars2’)
  3. wkcars.sort(‘cylinders’, wkcars2)
  4. cars2=cars.sort(‘DESCENDING origin’, out=’foobar’)
  5. cars.sort(‘type’).head()
  6. stat_results = stat.reg(model=’horsepower = Cylinders EngineSize’, by=’type’, data=wkcars.sort(‘type’))
  7. stat_results2 = stat.reg(model=’horsepower = Cylinders EngineSize’, by=’type’, data=wkcars.sort(‘type’,’work.cars’))
tail(obs=5)

display the last n rows of a table

Parameters:obs – the number of rows of the table that you want to display. The default is 5
Returns:
to_csv(file: str, opts: dict = {}) → str

This method will export a SAS Data Set to a file in CSV format.

Parameters:file – the OS filesystem path of the file to be created (exported from this SAS Data Set)
Returns:
to_df(method: str = 'MEMORY', **kwargs) → pandas.core.frame.DataFrame

Export this SAS Data Set to a Pandas Data Frame

Parameters:
  • method – defaults to MEMORY; the original method. CSV is the other choice which uses an intermediary csv file; faster for large data
  • kwargs
Returns:

Pandas data frame

to_df_CSV(tempfile: str = None, tempkeep: bool = False, **kwargs) → pandas.core.frame.DataFrame

Export this SAS Data Set to a Pandas Data Frame via CSV file

Parameters:
  • tempfile – [optional] an OS path for a file to use for the local CSV file; default it a temporary file that’s cleaned up
  • tempkeep – if you specify your own file to use with tempfile=, this controls whether it’s cleaned up after using it
  • kwargs
Returns:

Pandas data frame

Return type:

‘pd.DataFrame’

to_frame(**kwargs) → pandas.core.frame.DataFrame

Export this SAS Data Set to a Pandas Data Frame

Parameters:kwargs
Returns:Pandas data frame
Return type:‘pd.DataFrame’
top(var: str, n: int = 10, order: str = 'freq', title: str = '') → object

Return the most commonly occuring items (levels)

Parameters:
  • var – the CHAR variable (column) you want to count
  • n – the top N to be displayed (defaults to 10)
  • order – default to most common use order=’data’ to get then in alphbetic order
  • title – an optional Title for the chart
Returns:

Data Table

where(where: str) → saspy.sasbase.SASdata

This method returns a clone of the SASdata object, with the where attribute set. The original SASdata object is not affected.

Parameters:where – the where clause to apply
Returns:SAS data object

Procedure Syntax Statements

class saspy.SASProcCommons(session, *args, **kwargs)

Bases: object

SAS Results

class saspy.SASresults(attrs, session, objname, nosub=False, log='')

Bases: object

Return results from a SAS Model object

ALL()

This method shows all the results attributes for a given object

SAS Procedures

Utility

class saspy.SASutil(session, *args, **kwargs)

Bases: object

This class is for SAS BASE procedures to be called as python3 objects and use SAS as the computational engine

This class and all the useful work in this package require a licensed version of SAS.

To add a new procedure do the following:

  1. Create a new method for the procedure

  2. Create the set of required statements. If there are no required statements then create an empty set {}

  3. Create the legal set of statements. This can often be obtained from the documentation of the procedure. ‘procopts’ should always be included in the legal set to allow flexibility in calling the procedure.

  4. Create the doc string with the following parts at a minimum:

    • Procedure Name
    • Required set
    • Legal set
    • Link to the procedure documentation
  5. Add the return call for the method using an existing procedure as an example

  6. Verify that all the statements in the required and legal sets are listed in _makeProcCallMacro method of sasproccommons.py

  7. Write at least one test to exercise the procedures and include it in the appropriate testing file

hpbin(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPBIN procedure

required_set = {}

legal_set= {'cls', 'code', 'grow', 'id', 'model', 'out', 'partition', 'performance', 'prune', 'rules'}

cls is an alias for the class statement For more information on the statements see the Documentation link. Documentation link: http://support.sas.com/documentation/cdl/en/stathpug/68163/HTML/default/viewer.htm#stathpug_hpsplit_syntax.htm

Parameters:kwargs – dict
Returns:SAS result object
hpimpute(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPIMPUTE procedure

required_set = {'impute'}

legal_set = {'input', 'impute', 'performance', 'id', 'freq', 'code', 'procopts'}

For more information on the statements see the Documentation link. Documentation link: http://support.sas.com/documentation/cdl/en/stathpug/68163/HTML/default/viewer.htm#stathpug_hpsplit_syntax.htm

Parameters:kwargs – dict
Returns:SAS result object
hpsample(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPSAMPLE procedure

required_set = {}

legal_set= {'cls', 'code', 'grow', 'id', 'model', 'out' 'partition', 'performance', 'prune', 'rules'}

cls is an alias for the class statement For more information on the statements see the Documentation link. Documentation link: http://support.sas.com/documentation/cdl/en/stathpug/68163/HTML/default/viewer.htm#stathpug_hpsplit_syntax.htm

Parameters:kwargs – dict
Returns:SAS result object

Machine Learning (SAS Enterprise Miner)

class saspy.SASml(session, *args, **kwargs)

Bases: object

This class is for SAS Enterprise Miner procedures to be called as python3 objects and use SAS as the computational engine

This class and all the useful work in this package require a licensed version of SAS.

To add a new procedure do the following:

  1. Create a new method for the procedure

  2. Create the set of required statements. If there are no required statements then create an empty set {}

  3. Create the legal set of statements. This can often be obtained from the documentation of the procedure. ‘procopts’ should always be included in the legal set to allow flexibility in calling the procedure.

  4. Create the doc string with the following parts at a minimum:

    • Procedure Name
    • Required set
    • Legal set
    • Link to the procedure documentation
  5. Add the return call for the method using an existing procedure as an example

  6. Verify that all the statements in the required and legal sets are listed in _makeProcCallMacro method of sasproccommons.py

  7. Write at least one test to exercise the procedures and include it in the appropriate testing file

cluster(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPCLUS procedure

required_set = {'input'}

legal_set= {'freq', 'input', 'id', 'score'}

Documentation link: https://support.sas.com/documentation/solutions/miner/emhp/14.1/emhpprcref.pdf

Parameters:kwargs – dict
Returns:SAS result object
forest(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPFOREST procedure

required_set = {'input', 'target'}

legal_set = {'freq', 'input', 'id', 'target', 'save', 'score'}

Documentation link: https://support.sas.com/documentation/solutions/miner/emhp/14.1/emhpprcref.pdf

Parameters:kwargs – dict
Returns:SAS result object
hp4score(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HP4SCORE procedure

required_set = {}

legal_set = {'id', 'importance', 'performance', 'score', 'procopts'}

Documentation link: https://support.sas.com/documentation/solutions/miner/emhp/14.1/emhpprcref.pdf

Parameters:kwargs – dict
Returns:SAS result object
hpbnet(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPBNET procedure

required_set = {'input', 'target'}

legal_set = {'id', 'code', 'freq', 'partition', 'input', 'performance', 'target', 'output', 'procopts'}

Documentation link: http://go.documentation.sas.com/?docsetId=emhpprcref&docsetVersion=14.2&docsetTarget=emhpprcref_hpbnet_toc.htm&locale=en

Parameters:kwargs – dict
Returns:SAS result object
neural(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPNEURAL procedure

required_set = {'input', 'target', 'train'}

legal_set = {'architecture', 'code', 'hidden', 'id', 'input', 'partition', 'score', 'target', 'train', 'procopts'}

Documentation link: https://support.sas.com/documentation/solutions/miner/emhp/14.1/emhpprcref.pdf

Parameters:kwargs – dict
Returns:SAS result object
treeboost(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the TREEBOOST procedure

required_set = {'input', 'target'}

legal_set = {'assess', 'code', 'freq', 'importance', 'input', 'performance', 'target', 'save', 'score', 'subseries', 'procopts'}

Documentation link: https://support.sas.com/documentation/solutions/miner/emhp/14.1/emhpprcref.pdf

Parameters:kwargs – dict
Returns:SAS result object
SASml(session, *args, **kwargs) This class is for SAS Enterprise Miner procedures to be called as python3 objects and use SAS as the computational engine

Statistics

class saspy.SASstat(session, *args, **kwargs)

Bases: object

This class is for SAS/STAT procedures to be called as python3 objects and use SAS as the computational engine

This class and all the useful work in this package require a licensed version of SAS.

To add a new procedure do the following:

  1. Create a new method for the procedure

  2. Create the set of required statements. If there are no required statements then create an empty set {}

  3. Create the legal set of statements. This can often be obtained from the documentation of the procedure. ‘procopts’ should always be included in the legal set to allow flexibility in calling the procedure.

  4. Create the doc string with the following parts at a minimum:

    • Procedure Name
    • Required set
    • Legal set
    • Link to the procedure documentation
  5. Add the return call for the method using an existing procedure as an example

  6. Verify that all the statements in the required and legal sets are listed in _makeProcCallMacro method of sasproccommons.py

  7. Write at least one test to exercise the procedures and include it in the appropriate testing file

factor(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the PHREG procedure For more information on the statements see the Documentation link.

required_set = {}

legal_set = {'by', 'cls', 'freq', 'paired', 'var', 'weight', 'procopts'}

Documentation link: http://go.documentation.sas.com/?docsetId=statug&docsetVersion=14.2&docsetTarget=statug_factor_overview.htm&locale=en

Parameters:kwargs – dict
Returns:SAS result object
glm(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the GLM procedure

For more information on the statements see the Documentation link.

required_set={'model'}

legal_set= {'absorb', 'by', 'cls', 'contrast', 'estimate', 'freq', 'id', 'lsmeans', 'manova', 'means', 'model', 'out', 'random', 'repeated', 'test', 'weight'}

cls is an alias for the class statement

Documentation link: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_glm_toc.htm

Parameters:kwargs – dict
Returns:SAS result object
hplogistic(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPLOGISTIC procedure

For more information on the statements see the Documentation link.

required_set={'model'}

legal_set= {'by', 'cls', 'code', 'freq', 'id', 'model', 'out', 'partition', 'score', 'selection', 'weight'}

cls is an alias for the class statement Documentation link: https://support.sas.com/documentation/onlinedoc/stat/141/hplogistic.pdf

Parameters:kwargs – dict
Returns:SAS result object
hpreg(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPREG procedure For more information on the statements see the Documentation link.

required_set={'model'}

legal_set = {'by', 'cls', 'code', 'freq', 'id', 'model', 'out', 'partition', 'performance', 'score', 'selection', 'weight'}

cls is an alias for the class statement

Documentation link: https://support.sas.com/documentation/onlinedoc/stat/141/hpreg.pdf

Parameters:kwargs – dict
Returns:SAS result object
hpsplit(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the HPSPLIT procedure

required_set = {}

legal_set= {'cls', 'code', 'grow', 'id', 'model', 'out', 'partition', 'performance', 'prune', 'rules'}

cls is an alias for the class statement

For more information on the statements see the Documentation link. Documentation link: http://support.sas.com/documentation/cdl/en/stathpug/68163/HTML/default/viewer.htm#stathpug_hpsplit_syntax.htm :param kwargs: dict :return: SAS result object

logistic(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the LOGISTIC procedure

For more information on the statements see the Documentation link.

required_set={'model'}

legal_set= {'by', 'cls', 'contrast', 'effect', 'effectplot', 'estimate', 'exact', 'freq', 'lsmeans', 'oddsratio', 'out', 'roc', 'score', 'slice', 'store', 'strata', 'units', 'weight'}

cls is an alias for the class statement

Documentation link: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_logistic_toc.htm

The PROC LOGISTIC and MODEL statements are required. The CLASS and EFFECT statements (if specified) must precede the MODEL statement, and the CONTRAST, EXACT, and ROC statements (if specified) must follow the MODEL statement.

Parameters:kwargs – dict
Returns:SAS result object
mixed(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the MIXED procedure

cls is an alias for the class statement For more information on the statements see the Documentation link.

required_set={'model'}

legal_set= {'by', 'cls', 'code', 'contrast', 'estimate', 'id', 'lsmeans', 'model', 'out', 'random', 'repeated', 'slice', 'weight'}

Documentation link: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_mixed_toc.htm

Parameters:kwargs – dict
Returns:SAS result object
phreg(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the PHREG procedure For more information on the statements see the Documentation link.

required_set = {'model'}

``legal_set = {‘assess’, ‘bayes’, ‘by’, ‘cls’, ‘contrast’, ‘freq’, ‘effect’, ‘estimate’,
‘hazardratio’, ‘id’, ‘lsmeans’, ‘lsmestimate’, ‘model’, ‘out’, ‘roc’, ‘random’, ‘slice’, ‘store’, ‘strata’, ‘test’, ‘weight’, ‘procopts’}``

cls is an alias for the class statement

Documentation link: http://go.documentation.sas.com/?docsetId=statug&docsetTarget=statug_phreg_toc.htm&docsetVersion=14.2&locale=en

Parameters:kwargs – dict
Returns:SAS result object
reg(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the REG procedure

For more information on the statements see the Documentation link.

required_set={'model'}

legal_set= {'add', 'by', 'code', 'id', 'var', 'lsmeans', 'model', 'random', 'repeated', 'slice', 'test', 'weight', 'out'}

Documentation link: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_reg_syntax.htm

Parameters:kwargs – dict
Returns:SAS result object
tpspline(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the TPSPLINE procedure

For more information on the statements see the Documentation link.

required_set = {'model'}

legal_set = {'by', 'freq', 'id', 'model', 'output', 'score', 'procopts'}

cls is an alias for the class statement

Documentation link: http://support.sas.com/documentation/cdl/en/statug/68162/HTML/default/viewer.htm#statug_tpspline_toc.htm

Parameters:kwargs – dict
Returns:SAS result object
ttest(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the PHREG procedure For more information on the statements see the Documentation link.

required_set = {}

legal_set = {'by', 'cls', 'freq', 'paired', 'var', 'weight', 'procopts'}

cls is an alias for the class statement

Documentation link: http://go.documentation.sas.com/?docsetId=statug&docsetVersion=14.2&docsetTarget=statug_ttest_overview.htm&locale=en

Parameters:kwargs – dict
Returns:SAS result object

Econometic and Time Series

class saspy.SASets(session, *args, **kwargs)

Bases: object

This class is for SAS/ETS procedures to be called as python3 objects and use SAS as the computational engine

This class and all the useful work in this package require a licensed version of SAS.

To add a new procedure do the following:

  1. Create a new method for the procedure

  2. Create the set of required statements. If there are no required statements then create an empty set {}

  3. Create the legal set of statements. This can often be obtained from the documentation of the procedure. ‘procopts’ should always be included in the legal set to allow flexibility in calling the procedure.

  4. Create the doc string with the following parts at a minimum:

    • Procedure Name
    • Required set
    • Legal set
    • Link to the procedure documentation
  5. Add the return call for the method using an existing procedure as an example

  6. Verify that all the statements in the required and legal sets are listed in _makeProcCallMacro method of sasproccommons.py

  7. Write at least one test to exercise the procedures and include it in the appropriate testing file

arima(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the ARIMA procedure

required_set={'identify'}

legal_set={ 'by', 'identify', 'estimate', 'outlier', 'forecast', 'out'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_arima_syntax.htm

esm(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the ESM procedure

required_set = {}

legal_set = { 'by', 'id', 'forecast', 'out'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_esm_syntax.htm

timedata(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the TIMEDATA procedure

required_set = {}

legal_set = {'by', 'id', 'fcmport', 'out', 'outarrays', 'outscalars', 'var', 'prog_stmts'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_timedata_syntax.htm

timeid(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the TIMEID procedure

required_set = {}

legal_set = { 'by', 'id', 'out'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_timeid_syntax.htm

timeseries(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the TIMESERIES procedure

required_set={'id'}

legal_set={ 'by', 'corr', 'crosscorr', 'decomp', 'id', 'season', 'trend', 'var', 'crossvar', 'out'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_timeseries_syntax.htm

ucm(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the UCM procedure

required_set={'model'}

legal_set= {'autoreg', 'blockseason', 'by', 'cycle', 'deplag', 'estimate', 'forecast', 'id', 'irregular', 'level', 'model', 'nloptions', 'performance', 'out', 'outlier', 'randomreg', 'season', 'slope', 'splinereg', 'splineseason'}

Documentation link: http://support.sas.com/documentation/cdl//en/etsug/68148/HTML/default/viewer.htm#etsug_ucm_syntax.htm

Quality Control

class saspy.SASqc(session, *args, **kwargs)

Bases: object

This class is for SAS/QC procedures to be called as python3 objects and use SAS as the computational engine This class and all the useful work in this package require a licensed version of SAS.

To add a new procedure do the following:

  1. Create a new method for the procedure

  2. Create the set of required statements. If there are no required statements then create an empty set {}

  3. Create the legal set of statements. This can often be obtained from the documentation of the procedure. ‘procopts’ should always be included in the legal set to allow flexibility in calling the procedure.

  4. Create the doc string with the following parts at a minimum:

    • Procedure Name
    • Required set
    • Legal set
    • Link to the procedure documentation
  5. Add the return call for the method using an existing procedure as an example

  6. Verify that all the statements in the required and legal sets are listed in _makeProcCallMacro method of sasproccommons.py

  7. Write at least one test to exercise the procedures and include it in the appropriate testing file

capability(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the CUSUM procedure required_set = {}

legal_set = {'cdfplot', 'comphist', 'histogram', 'inset', 'intervals', 'output', 'ppplot', 'probplot', 'qqplot', 'freq', 'weight', 'id', 'by', 'spec'}

Documentation link: http://support.sas.com/documentation/cdl/en/qcug/68161/HTML/default/viewer.htm#qcug_capability_sect001.htm

cusum(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the CUSUM procedure

required_set = {}

legal_set = {'by','xchart'}

Documentation link: http://support.sas.com/documentation/cdl/en/qcug/68161/HTML/default/viewer.htm#qcug_cusum_sect001.htm

macontrol(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the MACONTROL procedure

required_set = {}

Documentation link: http://support.sas.com/documentation/cdl/en/qcug/68161/HTML/default/viewer.htm#qcug_macontrol_toc.htm

shewhart(**kwargs: dict) → saspy.sasresults.SASresults

Python method to call the SHEWHART procedure

Documentation link: http://support.sas.com/documentation/cdl/en/qcug/68161/HTML/default/viewer.htm#qcug_shewhart_toc.htm