2011-05-12 199 views

回答

1

你可以具体谈谈在您粘贴数据,所以也许如果你跟踪你想要的下一个更新的位置去,你可以使用类似下面的它有贴:

data _null_; 
    set try; 
    file dde "EXCEL|sheet!R10C1:R150C20" notab lrecl=2000; #sheet & cell refs; 
    put var1 var2 varn; 
run; 

我以前没有使用过,因此我无法进一步评论。

但是,我建议的方法是将每月更新添加到SAS中的滚动历史数据集,然后将所有数据导出到Excel。您可以更好地控制格式以及将来在SAS内部而不是在Excel中进行的任何分析。

0

当然 - 使用VBA & IOM!这应该是诀窍:

Dim obSAS As SAS.Workspace 
Dim obWorkspaceManager As New SASWorkspaceManager.WorkspaceManager 
Dim obConnection As New ADODB.Connection 

Sub Connect_to_SAS() 
    Dim obServerDef As New SASWorkspaceManager.ServerDef 
    Dim xmlString As String 
    Dim errorXML As String 
    Dim myUserid As String 
    Dim myPwrd As String 
    Dim myPort As String 
    Dim myServer As String 

    ' Enter these params 
    myPort = 8561 
    myServer = "blah.companyname.com" 
    myUserid = "[email protected]" 
    mytargetsheet = "Sheet1" ' where the data is going 
    mytargetrow = 2 ' where the data gets pasted 

    ' connect to sas 
    obServerDef.Port = myPort 
    obServerDef.Protocol = ProtocolBridge 
    obServerDef.MachineDNSName = myServer 
    myPwrd = InputBox("User = " & myUserid & vbCrLf & vbCrLf & _ 
    "Please enter SAS password below", "Login Prompt", "Password") 
    If myPwrd = "" Then End 
    Set obSAS = obWorkspaceManager.Workspaces.CreateWorkspaceByServer(_ 
     "My Ref", VisibilityProcess, obServerDef, myUserid, myPwrd, xmlString) 
    If (Len(errorXML) > 0) Then MsgBox errorXML 
    'submit your sas code 
    obSAS.LanguageService.Submit "data x; x=1; run;" 
    ' retrieve data (cols not needed as we are doing an append) 
    Dim obRecordSet As New ADODB.Recordset 
    obConnection.Open "provider=sas.iomprovider.1; SAS Workspace ID=" _ 
     + obSAS.UniqueIdentifier 
    obRecordSet.Open "work.x", obConnection, adOpenStatic, adLockReadOnly _ 
     , adCmdTableDirect 
    Sheets(mytargetsheet).Cells(mytargetrow, 1).CopyFromRecordset obRecordSet 
    ' close session 
    obWorkspaceManager.Workspaces.RemoveWorkspace obSAS 
    obSAS.Close 
End Sub