<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Run a SAS program from Visual Basic in Excel in Microsoft Integration with SAS</title>
    <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23888#M461</link>
    <description>&lt;P&gt;If you are using SAS Add-in for Microsoft Office (AMO), there are a couple custom tasks (written by Chris Hemedinger) that will allow you to simply submit code from AMO. Here is one:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/onlinedoc/guide/customtasks/samples/SASProgramRunnerExample.zip" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/guide/customtasks/samples/SASProgramRunnerExample.zip&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE: Starting in AMO 7.13 release, you can &lt;A href="http://blogs.sas.com/content/sasdummy/2017/05/30/sas-programs-amo/" target="_self"&gt;create and run SAS programs in SAS Add-in for Microsoft Office&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; If you don't have AMO, it's a little more involved, but you can submit code via VBA using the LanguageService. I can send sample code (as-is) if desired.&lt;BR /&gt; &lt;BR /&gt; Casey&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2017 13:35:59 GMT</pubDate>
    <dc:creator>CaseySmith</dc:creator>
    <dc:date>2017-08-15T13:35:59Z</dc:date>
    <item>
      <title>Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23886#M459</link>
      <description>Hi !&lt;BR /&gt;
&lt;BR /&gt;
I'd like to just open the SAS software and then execute a program from Excel.&lt;BR /&gt;
&lt;BR /&gt;
Is there a syntax in Visual Basic for that?&lt;BR /&gt;
&lt;BR /&gt;
R.M.</description>
      <pubDate>Tue, 18 May 2010 13:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23886#M459</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-05-18T13:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23887#M460</link>
      <description>Recommended Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
+"visual basic" site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Tue, 18 May 2010 13:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23887#M460</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-05-18T13:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23888#M461</link>
      <description>&lt;P&gt;If you are using SAS Add-in for Microsoft Office (AMO), there are a couple custom tasks (written by Chris Hemedinger) that will allow you to simply submit code from AMO. Here is one:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/onlinedoc/guide/customtasks/samples/SASProgramRunnerExample.zip" target="_blank"&gt;http://support.sas.com/documentation/onlinedoc/guide/customtasks/samples/SASProgramRunnerExample.zip&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE: Starting in AMO 7.13 release, you can &lt;A href="http://blogs.sas.com/content/sasdummy/2017/05/30/sas-programs-amo/" target="_self"&gt;create and run SAS programs in SAS Add-in for Microsoft Office&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt; If you don't have AMO, it's a little more involved, but you can submit code via VBA using the LanguageService. I can send sample code (as-is) if desired.&lt;BR /&gt; &lt;BR /&gt; Casey&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2017 13:35:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23888#M461</guid>
      <dc:creator>CaseySmith</dc:creator>
      <dc:date>2017-08-15T13:35:59Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23889#M462</link>
      <description>&amp;gt; LanguageService.  I can send sample code (as-is) if&lt;BR /&gt;
&amp;gt; desired.&lt;BR /&gt;
&lt;BR /&gt;
Why don't you post the code here for the rest of the forum participants?</description>
      <pubDate>Thu, 20 May 2010 10:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23889#M462</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2010-05-20T10:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23890#M463</link>
      <description>I debated posting it, but was afraid it would clutter the thread.  But since you ask, here goes...&lt;BR /&gt;
I put together the sample VBA code below and ran it in Excel.  You have to have SAS Integration Technologies client (standalone, or bundled with AMO and EG) installed on the machine to be able to add the required references to the SAS type libraries in the VBA editor in Excel.  There are some help files (.chm) in the Integration Technologies installation folder that should provide some guidance on those interfaces.&lt;BR /&gt;
&lt;BR /&gt;
Good luck!&lt;BR /&gt;
Casey&lt;BR /&gt;
&lt;BR /&gt;
Note: The sample uses the 9.2 interfaces, but I'd expect similar code to work in 9.1.3.  The sample also connects to a server defined in metadata, but you should be able to change the code to connect to your local server if preferred.&lt;BR /&gt;
&lt;BR /&gt;
============================&lt;BR /&gt;
&lt;BR /&gt;
'Add reference to "SAS: Integrated Object Model (IOM)..." and "SASObjectManager ..." (optional)&lt;BR /&gt;
&lt;BR /&gt;
Sub SubmitCodeTest()&lt;BR /&gt;
    Dim ws As workspace&lt;BR /&gt;
    Dim code As String&lt;BR /&gt;
    Dim log As String&lt;BR /&gt;
    &lt;BR /&gt;
    Set ws = ConnectToServerUsingObjectFactory()&lt;BR /&gt;
    code = "data tmp; set sashelp.class; run;"&lt;BR /&gt;
    log = SubmitCode(ws, code)&lt;BR /&gt;
    MsgBox log&lt;BR /&gt;
End Sub&lt;BR /&gt;
&lt;BR /&gt;
Function ConnectToServerUsingObjectFactory() As workspace&lt;BR /&gt;
&lt;BR /&gt;
On Error GoTo ErrHandler&lt;BR /&gt;
&lt;BR /&gt;
'Requires reference to "SASObjectManager 1.1 Type Library"&lt;BR /&gt;
Dim obObjectFactory As ObjectFactoryMulti2&lt;BR /&gt;
'Requires reference to "SAS: Integrated Object Model (IOM) (SAS System 9.2) Type Library"&lt;BR /&gt;
Dim obSAS As workspace&lt;BR /&gt;
Dim obObjectKeeper As New SASObjectManager.objectKeeper&lt;BR /&gt;
&lt;BR /&gt;
Set obObjectFactory = CreateObject("SASObjectManager.ObjectFactoryMulti2")&lt;BR /&gt;
&lt;BR /&gt;
obObjectFactory.LogEnabled = True&lt;BR /&gt;
&lt;BR /&gt;
' Use the SAS Object Manager to establish a SAS workspace object.&lt;BR /&gt;
Set obSAS = obObjectFactory.CreateObjectByLogicalName("SASApp - Logical Workspace Server", "")&lt;BR /&gt;
&lt;BR /&gt;
MsgBox obObjectFactory.GetCreationLog(False, True)&lt;BR /&gt;
MsgBox obSAS.UniqueIdentifier&lt;BR /&gt;
&lt;BR /&gt;
'Add the workspace to the object keeper&lt;BR /&gt;
obObjectKeeper.AddObject 1, "", obSAS&lt;BR /&gt;
&lt;BR /&gt;
Set ConnectToServerUsingObjectFactory = obSAS&lt;BR /&gt;
&lt;BR /&gt;
Exit Function&lt;BR /&gt;
&lt;BR /&gt;
ErrHandler:&lt;BR /&gt;
MsgBox Err.Description&lt;BR /&gt;
&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Function SubmitCode(workspace As workspace, code As String) As String&lt;BR /&gt;
&lt;BR /&gt;
    Dim ls As SAS.LanguageService&lt;BR /&gt;
    Dim logBuffer As String&lt;BR /&gt;
    Set ls = workspace.LanguageService&lt;BR /&gt;
        &lt;BR /&gt;
    'if we submit asynchronously, we'd have to add a sink and wait to retrieve the log until signalled&lt;BR /&gt;
    ls.Async = False&lt;BR /&gt;
    ls.Submit code&lt;BR /&gt;
&lt;BR /&gt;
    'get the log&lt;BR /&gt;
    logBuffer = ls.FlushLog(100000)&lt;BR /&gt;
    &lt;BR /&gt;
    'Could use FlushLogLines to get log instead&lt;BR /&gt;
    'Dim carriageControls() As LanguageServiceCarriageControl&lt;BR /&gt;
    'Dim lineTypes() As LanguageServiceLineType&lt;BR /&gt;
    'Dim logLines() As String&lt;BR /&gt;
    'ls.FlushLogLines 8192, carriageControls, lineTypes, logLines&lt;BR /&gt;
    'For Each line In logLines&lt;BR /&gt;
    '    logBuffer = logBuffer &amp;amp; line &amp;amp; vbCrLf&lt;BR /&gt;
    'Next line&lt;BR /&gt;
&lt;BR /&gt;
    SubmitCode = logBuffer&lt;BR /&gt;
End Function&lt;BR /&gt;
&lt;BR /&gt;
Function AssignLibref(workspace As workspace, libraryName As String, path As String)&lt;BR /&gt;
    'Assign a libref using the DataService AssignLibref method...&lt;BR /&gt;
    workspace.DataService.AssignLibref libraryName, "", path, ""&lt;BR /&gt;
End Function</description>
      <pubDate>Fri, 21 May 2010 18:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23890#M463</guid>
      <dc:creator>CaseySmith</dc:creator>
      <dc:date>2010-05-21T18:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23891#M464</link>
      <description>The page&lt;BR /&gt;
&lt;A href="http://support.sas.com/rnd/datavisualization/BridgeForESRI/V1/stored_process_code.htm" target="_blank"&gt;http://support.sas.com/rnd/datavisualization/BridgeForESRI/V1/stored_process_code.htm&lt;/A&gt;&lt;BR /&gt;
was helpful.  But how do we modify the syntax to&lt;BR /&gt;
&lt;BR /&gt;
1.  pass dataset in excel worksheet to the macro variable ds local to myprgrm?&lt;BR /&gt;
&lt;BR /&gt;
Would I need a dde type of statement in myprgrm to convert the Excel worksht that I pass to SAS via VBA into SAS dataset?&lt;BR /&gt;
&lt;BR /&gt;
2.  pass dataset in a folder (non-excel) to the macro variable ds local to myprgrm?&lt;BR /&gt;
&lt;BR /&gt;
Thanks very much in advance.</description>
      <pubDate>Mon, 21 Mar 2011 19:16:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23891#M464</guid>
      <dc:creator>sasfrum2011</dc:creator>
      <dc:date>2011-03-21T19:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23892#M465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I get this error: "Argument&amp;nbsp; not optional". Do you known why?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 May 2014 10:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23892#M465</guid>
      <dc:creator>huyns</dc:creator>
      <dc:date>2014-05-14T10:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23893#M466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Welcome to the forum. A quick internet search on your error message provided the following link:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/102s19ky.aspx" title="http://msdn.microsoft.com/en-us/library/102s19ky.aspx"&gt;Argument not optional (Visual Basic)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sounds like an argument is missing, possibly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is good practice to start a new question when you need something answering, as mentioned in &lt;A __default_attr="2263" __jive_macro_name="document" class="jive_macro jive_macro_document" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need more information then you'll need to supply more information, e.g. the relevant part of your program, which would be good to do in a new question, as already mentioned.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the error is occurring in VB then it might be worth trying to post your question to a VB forum, if you haven't already or if you can't get an answer here.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 14 May 2014 12:07:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23893#M466</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2014-05-14T12:07:59Z</dc:date>
    </item>
    <item>
      <title>Re: Run a SAS program from Visual Basic in Excel</title>
      <link>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23894#M467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. The code works and opens a whole new domain of possibilities. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have one problem, though:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How to get a macro variable's value into the VBA? My code needs to decide what task to run next based on the SAS' result, and the task might be performed outside the SAS ecosystem (in Oracle or R for instance). &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 10:12:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Microsoft-Integration-with-SAS/Run-a-SAS-program-from-Visual-Basic-in-Excel/m-p/23894#M467</guid>
      <dc:creator>AdamRyczkowski</dc:creator>
      <dc:date>2015-05-26T10:12:20Z</dc:date>
    </item>
  </channel>
</rss>

