Getting Feedback from the SAS Session

SAS provides two properties, RC and ResultString, that make it possible to pass information from the SAS session that you are automating back to the application that is controlling it. RC can contain a number; ResultString can contain a text string.
To set the values of these properties from within the SAS session, use the SETRC function with this syntax:
error=SETRC("result-string", rc-number);
where result-string is the value to be assigned the ResultString property, and rc-number is the value to be assigned to the RC property.
For example, you can use the Submit method to submit DATA step code that returns an error code as part of its processing. You can then check the value of that error using the RC or ResultString property. Here is a Visual Basic example of this:
Private Delcare Sub Sleep Lib “kernel32” (ByVal dwMilliseconds As Long)

Using Visual Studio 2010 vb.net, I had to change this to:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
Handles Button1.Click
        Dim OleSAS As Object
        Dim x = 0
        Dim Response
        OleSAS = CreateObject("SAS.Application")
        OleSAS.Submit("data _null_;error=setrc('Error string', 2.0);put error; run;")
        Sleep(500)
        Do While x = 0
            If (OleSAS.Busy) Then
                Sleep(500)
            Else
                If (OleSAS.RC <> 0) Then Response = MsgBox(OleSAS.ResultString,
                vbOKOnly, "Error Message is")
                x = 1
            End If
        Loop
    End Sub