You can connect to a SAS server and work directly with SAS data sets. Making connections and interacting with SAS data sets is scriptable through JSL. For more information, see 连接至 SAS 元数据服务器 in the Using JMP book.
First, use the Meta Connect() command to connect to a SAS metadata server:
connected = Meta Connect( "MyMetadataServer", port );
To specify the SAS version for the metadata server, use the SASVersion named argument:
connected = Meta Connect( "MyMetadataServer", port, SASVersion("9.4") );
If you supply only the machine name (for example, myserver.mycompany.com) and the port, you are prompted to provide the authentication domain, your user name, and your password. You can also specify all that in JSL:
connected = Meta Connect( "MyMetadataServer", port, "authdomain", "user name", "password" );
When you are finished using the SAS metadata server, use Meta Disconnect( ) to disconnect the connection. No arguments are necessary; the command closes the current metadata server connection.
Meta Get Repositories();
{"Foundation"}
Meta Set Repository( "Foundation" );
mylist = Meta Get Servers();
{"SASMain", "Schroedl", "SASMain_ja", "SASMain_zh", "SASMain_ko", "SASMain_fr", "SASMain_de", "SASMain_Unicode"}
conn = SAS Connect( "SASMain" );
Now you can send Disconnect and Connect messages to the conn object to close and open the SAS connection.
conn << Disconnect();
conn << Connect();
This is an example of using an object and messages with SAS server connections. You might have also connected to SAS servers using global functions. If so, the Disconnect and Connect messages do not affect those global connections. However, if there is no active global connection, that global connection is set to the connection opened by the object.
When you connect to a SAS server, use Connect Libraries to automatically connect metadata-defined libraries.
conn = SAS Connect( "SASMain", Connect Libraries( 1 ) );
To connect specific libraries later, use the SAS Connect Libref function or Connect Libref message to a SAS server object.
After you connect to a SAS server, use the Get Lib Ref() command to view the libraries on that server:
conn << Get Lib Refs();
{"BOOKS", "EGSAMP", "GENOMICS", "GISMAPS", "JMPSAMP", "JMPTEST",
"MAILLIB", "MAPS", "OR_GEN", "ORION_RE", "ORSTAR", "SASHELP",
"SASUSER", "TEMPDATA", "TSERIES", "V6LIB", "WORK", "WRSTEMP"}
conn << Assign Lib Refs( "MyLib", "$DOCUMENTS\data" );
conn << Assign Lib Refs( "MyLib", "$DOCUMENTS" );
datasets << Get Data Sets( "MyLib" );
{"ANDORRA", "ANDORRA2", "ANYVARNAME", "BOOKS", "BOOKSCOPYNOT", "BOOKS_VIEW", "CATEGORIES", "DATETIMETESTS", "MOREUGLY", "NOTTOOUGLY", "PAYPERVIEW", "PUBLISHERS", "PURCHASES", "PURCHASES_FULL",
conn << Import Data( "MyLib", "PURCHASES" );
conn << Import Data( librefs[1], datasets[12] );
conn << Import Data( "MyLib.PURCHASES" );
conn << Get Var Names( "MyLib.PURCHASES" );
{"purchaseyear", "purchasemonth", "purchaseday", "bookid", "catid",
"pubid", "price", "cost"}
conn << Import Data( librefs[1], datasets[12], columns( bookvars[1], bookvars[2], bookvars[4] ) );
To save a JMP data table or an imported SAS Data Set, use the SAS Export Data() command:
conn << Export Data( dt, librefs[1], datasets[4], ReplaceExisting );
stp = Meta Get Stored Process( "Samples/Stored Processes/Sample: Hello World" );
stp << Run();
conn << Submit( "proc print data=sashelp.class; run;" );
conn << Submit( "SAS Code" <,No Output Window(True|False)> <,Get Log(True|False )> );
conn << Get Log();
Get Log() returns the contents, which can be placed in a JSL variable and used like any JSL string.