SAS Objects

SASArgument

class SASDocumentation.SASObjects.SASArgument.SASArgument(rawStr)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Argument Class

This object exists as a definition for a “argument”. Currently used to define arguments parsed from a SAS Macro. It could be expanded to work with proc fcmp allowing for analysis of custom function arguements.

Name

Name of the Argument given

Type

Required or Optional

DefaultValue

If type is optional then the default value

DocString

Documentation String for the argument.

SASBaseObject

class SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

Bases: object

SAS Base Object Class

This object exists as the base object for most SAS objects and several functions for processing SAS program text in to SASObjects correctly.

regexFlags

Global regex flags

SASRegexDict

Identifies elements of the SAS program

SASKeywords

List of SAS reserved keywords

parse(SASObject, str)

Parses passed string for specified object from SASRegexDict

Parameters
  • - Str name of SAS Object to be parsed key for SASRegexDict (SASObjectName) –

  • - String of text to be parsed (str) –

Returns

List - Returns list of parsed strings

parseDataObjects(objectText)

Parses Data Objects Strings into SASDataObjects grabbing library.

Parameters

- String defintion of data object. (ObjectText) –

Returns

SASDataObject

splitDataObjects(str)

Splits a string into seperate data objects ignoring macro variables and brackets

Parameters

- String containing one more data objects (str) –

Returns

list - Containing seperated data objects

validateSplitDataObjects(obj)

Validates a data object against SASKeywords and commonsense

Parameters

- Data object to be validated (DataObject) –

Returns

Bool - Data object is valid or not.

SASDataObject

class SASDocumentation.SASObjects.SASDataObject.SASDataObject(library, dataset, condition, startLine=None, endLine=None)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Data Object Class

This object exists as a definition for a SASDataset. Not a ‘Data’ statement but any reference to a dataset that exists in a piece of SAS Code. Including any inline conditions and libraries.

Library

Name of Library

Dataset

Name of Dataset

Condition

Any inline conditions applied to the dataset

StartLine

The inital line in the parent code where this appears

Type

optional

Endline

The final line of the datastatement

Type

optional

isNull()

Check if the self is a _null_ dataset

Returns

bool - True if _null_

SASDataObjectParser

class SASDocumentation.SASObjects.SASDataObjectParser.SASDataObjectParser

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Data Object Parser Class

Factory for creating DataObjects from text string

parseDataObjects(objectText, startLine=None, endLine=None)

Takes object text and parses out Data Objects

Parameters
  • - Raw text with DataObject defined within (objectText) –

  • startLine (optional) –

  • endLine (optional) –

Returns

list - List of validated SASDataObjects found in objectText

SASDatastep

class SASDocumentation.SASObjects.SASDatastep.SASDatastep(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASDataObjectParser.SASDataObjectParser

SAS Datastep Object

This object represents an entire SAS Datastep. Each input and output being a SASDataObject and such having the properties of a library, dataset name and condition where applicable

Inputs

List of DataObjects that are inputs to this step

Outputs

List of DataObjects that are outputs from this step

Head

Headline of datastep

Body

Body of datastep

StartLine

The inital line in the parent code where this appears

Type

optional

Endline

The final line of the datastatement

Type

optional

SASInclude

class SASDocumentation.SASObjects.SASInclude.SASInclude(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Include Object

This object represents a SAS include statement. This path can be followed programmatically to find additionl extra-project code.

path

Path defined in the include statement

posixPath

Web-friendly version of path

StartLine

The inital line in the parent code where this appears

Type

optional

Endline

The final line of the datastatement

Type

optional

SASLibname

class SASDocumentation.SASObjects.SASLibname.SASLibname(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Libname Object

This object represents a SAS libname statement.

name

Defined name of the library

path

Path defined in the libname statement

posixPath

Web-friendly version of path

StartLine

The inital line in the parent code where this appears

Type

optional

Endline

The final line of the datastatement

Type

optional

class SASDocumentation.SASObjects.SASLibname.SASSQLLibname(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS SQLLibname Object

name

Defined name of the library

server

Hosted SQL server for library

database

Database on the SQL server for library

schema

Defined schema for the library (default: dbo)

StartLine

The inital line in the parent code where this appears

Type

optional

Endline

The final line of the datastatement

Type

optional

This object represents a SAS SQLlibname statement. This is pulled from the %SQLLIB macro only.

SASMacro

class SASDocumentation.SASObjects.SASMacro.SASMacro(rawStr, startLine)

Bases: object

SAS Macro Class

This class represents a SAS Macro function, primarly an attempt to fit the SAS Macro into a python class/function documentation structure.

Name

Name of the Macro given

Arguments

List of SASArgument Objects

DocString

Documentation String for the argument.

Help

Help statement if present in the macro

getArgs(argStr)

Find all arguements in the macro definition line.

Parameters

- String containing defined arguments (argStr) –

Returns

list - List of SASArgument Objects

getDocString(docString)

Clean the doc string defintion of the macro

Parameters

- String containing macro docstring (docString) –

Returns

list - Docstring with comment delimiters removed

getHelp(helpString)

Clean the help string defintion of the macro

Parameters

- String containing macro helpString (helpString) –

Returns

list - Docstring with %put statments removed

SASProcedure

class SASDocumentation.SASObjects.SASProcedure.SASProcSQL(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASDataObjectParser.SASDataObjectParser

SAS Proc SQL Class

This class represents the PROC SQL statment. It is largely identical to the SASProcedure class except for handling the rawInput and rawOutputs from the code.

Inputs

List of DataObjects that are inputs to this step

Outputs

List of DataObjects that are outputs from this step

Procedure

SAS Procedure type

StartLine

The inital line in the parent code where this appears

Endline

The final line of the datastatement

class SASDocumentation.SASObjects.SASProcedure.SASProcedure(rawStr, startLine)

Bases: SASDocumentation.SASObjects.SASDataObjectParser.SASDataObjectParser

SAS Procedure Class

This class represents all SAS procedures, except PROC SQL. They are defined as a list of inputs, outputs and a procedure type which is the word after proc in the raw code.

Inputs

List of DataObjects that are inputs to this step

Outputs

List of DataObjects that are outputs from this step

Procedure

SAS Procedure type

StartLine

The inital line in the parent code where this appears

Endline

The final line of the datastatement

SASProgram

class SASDocumentation.SASObjects.SASProgram.SASProgram(file)

Bases: SASDocumentation.SASObjects.SASBaseObject.SASBaseObject

SAS Program Class

This class represents an entire .sas program. Seperating out macros, datasteps and procedures into predefined python objects. Included are several functions to read different aspects of the code correctly.

Name

Name of the SAS Program

Filename

Filename of the SAS Program

FilePath

Absolute file path of the SAS Program

LastUpdated

Current time

FileSize

Size of SAS Programfile

Macros

List of SAS Macros

Libnames

Two lists of defined SAS and SQL libnames

Datasteps

List of all datasteps found the in code

Procedures

list of all procedure found in the code

Inputs

List of all inputs in the code

Outputs

List of all outputs in the code

rawComments

a list of all comment blocks within the code

unCommentedCode

a version of the code with all comments/put statements removed.

findLine(str)

Find the line number of a given string. :param str - String to search for in the code:

Returns

int - Line number for string

getInputs()

Find all input objects from datasteps and procedures

Returns

list - List of input objects

getOutputs()

Find all output objects from datasteps and procedures

Returns

list - List of output objects

getUniqueDataObjects()

Create a list of unique data items based on name and library and a list of tuples denoting the lines where they occur.

Returns

dict - DataItem library,dataset tupple -> linestart,lineend tupple list

readDatasteps(rawDatasteps)

Read and process list of rawStrings into Objects

Returns

list - List of Objects

readIncludes(rawIncludes)

Read and process list of rawStrings into Objects

Returns

list - List of Objects

readLibnames(rawLibnames, libType)

Read and process list of rawStrings into Objects

Returns

list - List of Objects

readMacros(rawMacros)

Read and process list of rawStrings into Objects

Returns

list - List of Objects

readProcedures(rawProcedures)

Read and process list of rawStrings into Objects

Returns

list - List of Objects

SASProject

class SASDocumentation.SASObjects.SASProject.SASProject(projectPath)

Bases: object

buildMacroIndex()

Create a markdown formatted string containing all macros found within the project. This is used to generate the macroIndex for sphinx.

Returns

Markdown formatted string containing all macros and appropriate properties.

Return type

str

buildProgramDocumentation(SASProgram, FlowChart)

Generate a markdown string from a SASProgram object. A SASFlowChart is also generated if there are none null data objects present in the code.

Parameters
  • - A SAS Program Object (SASProgram) –

  • - The FlowChart object that corresponds to the SAS Program Object (FlowChart) –

Returns

MD structured full documentation for the given SASProgram

Return type

str

buildProject(outPath)

Create a _code.rst, _extcode.rst, macroIndex.md and _mindex.rst files. These are structural files used by sphinx to generate documentation and list locations of program documentation generated by the writeProgramDocumentation function.

This also calls the writeProgramDocumentation function which generates documentation for a list of SASPrograms

Parameters

outPath – Root outpath for documentation, these files are written to outpath/code

linkLines(startLine, endLine)

Create a sphinx/html complient hyperlink that links line numbers to raw code posted in the HTML build. The class lineJump is picked up in javascript post build.

Parameters
  • - Startline in the code of the object (startLine) –

  • - Endline in the code of the object (endLine) –

Returns

<a> tagged HTML markup of the startLine, endLine.

Return type

str

writeProgramDocumentation(programList, rstFile)

Loop over a list of SASProgram object and generate markdown documentation. This also generates the SASFlowChart object based on the program

Parameters
  • programList – A List of SASProgram objects to generate documentation for

  • rstFile – Specifies whether this is projectCode or externalCode and generates an appropriate rstfile to return

Returns

RST structured list of files processed for sphinx documenation to generate

tables of contents trees from.

Return type

str