Example

The following example illustrates the use of each SAS Event Stream Processing data type as input to and as output from a public Python function.
# 
#    Name: scalarsTest.py
# Purpose: Test the Python program for scalar types
#
# Inputs (name)         (type)
#       inString        String
#       inBool          Boolean
#       inLong          Long
#       inDouble        Double
#       inTimestamp     Long microseconds since 1960
#       inDatetime      Long seconds since 1960
#       inMoney         Double
#
# Outputs (name)        (type)
#       outString       String
#       outBool         Boolean
#       outLong         Long
#       outDouble       Double
#       outTimestamp    Long microseconds since 1960
#       outDatetime     Long seconds since 1960
#       outMoney        Double
#
# Note: Event stream processing presents the timestamp as
#       long microseconds since 1960 and datetime as long
#       seconds since 1960.

# Import the datetime module to perform datetime operations.
import datetime

def scalarsTest(inString, inBool, inLong, inDouble,
     inTimestamp, inDatetime, inMoney):
    "Output: outString, outBool, outLong, outDouble,
      outTimestamp, outDatetime, outMoney"
    
    if inString == None:
        outString = None
    else:
        # Convert the casing of the string input.
        outString = inString.swapcase()
    print ("\n inString=", inString, " outString=",
           outString, " (reverse case)")
    
    if inBool == None:
        outBool = None
    else:
        # Reverse value of the Boolean.
        outBool = not inBool
    print ("\n inBool=", inBool, " outBool=", outBool,
           " (not inBool)")
    
    if inLong == None:
        outLong = None
    else:
        # Add 10 to long.
        outLong = inLong + 10
    print ("\n inLong=", inLong, " outLong=", outLong,
           " (add 10)")
    
    if inDouble == None:
        outDouble = None
    else:
        # Add 10.1 to the double.
        outDouble = inDouble + 10.1
    print ("\n inDouble=", inDouble, " outDouble=", outDouble,
           " (add 10.1)")
    
    if inTimestamp == None:
        outTimestamp = None
    else:
        # Since this is defined as a stamp in event stream processing
        # schema, this number is long microseconds since 1960.
        # Add one second == 1000000 microseconds.
        outTimestamp = inTimestamp + 1000000
    print ("\n inTimestamp=", inTimestamp, " outTimestamp=",
           outTimestamp, " (add one second)")
    
    if inDatetime == None:
        outDatetime = None
    else:
        # Since this is defined as date in the event stream processing schema,
        # this number is long seconds since 1960.
        # Add one day.
        outDatetime = inDatetime + (3600 * 24)
    print ("\n inDatetime=", inDatetime, " outDatetime=", outDatetime,
           " (add one day)")
    
    if inMoney == None:
        outMoney = None
    else:
        # Add 25 cents.
        outMoney = inMoney + 0.25
    print ("\n inMoney=", inMoney, " outMoney=", outMoney,
           "(add 25 cents)")
    
        
    # Return all of the outputs.
    return outString, outBool, outLong, outDouble, outTimestamp,
     outDatetime, outMoney