BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SHI_KAI
Fluorite | Level 6

我是一名java程序员。我需要先实现一个功能,就是我开发的Java软件可以连接远程SAS服务器,传一个脚本给他执行,并将结果返回给我的程序。我尝试阅读了许多文件,但仍然没有准确的结果告诉我如何进行。请帮我

1 ACCEPTED SOLUTION
5 REPLIES 5
SHI_KAI
Fluorite | Level 6

Thank you for your reply. This method has been adopted by me before, but we have a session problem that cannot be solved. We need to run multiple scripts at the same time, but they must be executed in the same session in order to obtain the context of each other and execute successfully. If you use bat, you can only execute one script at a time sas 。 Do you know how to solve my problem?

whymath
Lapis Lazuli | Level 10
您可以借用静态包含的做法。即写一个新的脚本,该脚本内容为:
%inc "myscript1.sas";
%inc "myscript2.sas";
%inc "myscript3.sas";

然后使用批处理的方式运行该脚本。这样多个.sas文件就能够按预期的顺序执行了。
SHI_KAI
Fluorite | Level 6
thank!Then I may need to communicate with my colleagues in the statistics department. I know nothing about SAS。
GreenCode
SAS Employee

Java连接SAS服务器提交SAS代码运行例子:

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;

import org.omg.CORBA.StringHolder;

import com.sas.iom.SAS.IBinaryStream;
import com.sas.iom.SAS.IFileService;
import com.sas.iom.SAS.IFileref;
import com.sas.iom.SAS.ILanguageService;
import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.iom.SAS.StreamOpenMode;
import com.sas.iom.SASIOMDefs.OctetSeqHolder;
import com.sas.services.connection.BridgeServer;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.ManualConnectionFactoryConfiguration;
import com.sas.services.connection.Server;

public class DownloadOutput {

    /**
     * @param args
     */
    public static void main(String[] args) {
        try {
            String classID = Server.CLSID_SAS;
            String host = "t3207.na.sas.com";
            int port = 8591;
            Server server = new BridgeServer(classID, host, port);
            // TODO Auto-generated method stub
            ConnectionFactoryConfiguration cxfConfig = new ManualConnectionFactoryConfiguration(
                    server);
            ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();
            ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);
            String user = "sasdemo";
            String password = "Orion123";
            ConnectionInterface cx = cxf.getConnection(user, password);
            org.omg.CORBA.Object obj = cx.getObject();
            IWorkspace sasWorkspace = IWorkspaceHelper.narrow(obj);

            IFileService fileService = sasWorkspace.FileService();

            StringHolder outstring = new StringHolder();

            IFileref fileRef = fileService.AssignFileref("out", "TEMP", "", "",
                    outstring);

            ILanguageService languageService = sasWorkspace.LanguageService();

            String sasCode = "goptions reset=all gsfname=out gsfmode=replace dev=pdf; proc gchart data=sashelp.class;vbar age / discrete;run;quit;";

            languageService.Submit(sasCode);

            IBinaryStream fileStream = fileRef
                    .OpenBinaryStream(StreamOpenMode.StreamOpenModeForReading);

            BufferedOutputStream fos = new BufferedOutputStream(
                    new FileOutputStream("c:\\temp\\test.pdf"));
            boolean readMore = true;
            OctetSeqHolder tempData = new OctetSeqHolder();
            while (readMore) {
                fileStream.Read(1024, tempData);
                if (tempData.value.length == 0) {
                    readMore = false;
                } else {
                    fos.write(tempData.value);
                }
            }
            fileStream.Close();
            fos.close();
            cx.close();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

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!

Discussion stats
  • 5 replies
  • 2394 views
  • 2 likes
  • 3 in conversation