BookmarkSubscribeRSS Feed
yanivtz
Calcite | Level 5

Hi,

 

I am trying to run SAS from Excel, using VBA.

Very basic.

 

I am attaching the code. The error I am getting is: "the object could not be found; make sure it was previously added to the object keeper"

 

sub  Macro1 ()
    Dim obObjectFactory As New SASObjectManager.ObjectFactoryMulti2
   
    Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
   
    Dim obConnection As New ADODB.Connection
    Dim obRecordSet As New ADODB.Recordset
    Dim errorString As String
    Dim sourcebuffer As String
    Dim height As Variant
    Dim weight As Variant
    height = 180
    weight = 180
    Dim obServer As New SASObjectManager.ServerDef
   
    obServer.MachineDNSName = [myserver]
    obServer.Protocol = SASObjectManager.Protocols.ProtocolBridge
    obServer.Port = 8591

   If (obSAS Is Nothing) Then
   Set obSAS = obObjectFactory.CreateObjectByServer("sas", True, obServer, [login],[pwd])
  
   End If


sourcebuffer = "options sasautos=(sasautos,'X:\Actuarya\USERS\tzafiry\Madadim\bmi.sas');%bmi(" & height & "," & weight & ");"
obSAS.LanguageService.Submit sourcebuffer


obConnection.Open "provider=sas.iomprovider.1; SAS workspace ID=" + obSAS.UniqueIdentifier
obRecordSet.Open "work.result", obConnection, adOpenStatic, adLockReadOnly, adCmdTableDirect
obRecordSet.MoveFirst
bmi = obRecordSet(0).Value

End Sub

3 REPLIES 3
Astounding
PROC Star

When setting up SASAUTOS, the paths used should be to a folder not to an individual file.  Where you have this:

 

'X:\Actuarya\USERS\tzafiry\Madadim\bmi.sas'

 

Try replacing that with:

 

'X:\Actuarya\USERS\tzafiry\Madadim'

 

When you try to use %bmi, SAS will automatically search for its definition in a file named bmi.sas.

yanivtz
Calcite | Level 5

The code failed after executing:

 

obConnection.Open "provider=sas.iomprovider.1; SAS workspace ID=" + obSAS.UniqueIdentifier

 

I am getting an error that "the object could not be found; make sure it was previously added to the object keeper".

yanivtz
Calcite | Level 5

Still looking for a solution... Thanks

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 1354 views
  • 0 likes
  • 2 in conversation