Scripting Guide > Extending JMP > Work with SAS > Connect to a SAS Metadata Server
Publication date: 08/13/2020

Connect to a SAS Metadata Server

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 information about connecting to a metadata server in the JMP interface, see Connect to a SAS Metadata Server in Using JMP.

Note: If you connect to a physical workspace server, there is no metadata server involved, so metadata security is never applied. You must connect to a SAS Metadata Server and then connect to a logical workspace server. Then metadata security is enforced on the metadata-defined libraries you access.

Make the Connection

First, use the Meta Connect() function 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.

You can see the repositories that are available on a metadata server and set the one that you want to use:

Meta Get Repositories();

{"Foundation"}

Meta Set Repository( "Foundation" );

Note that if there is only one repository available, it is selected automatically and you do not need to explicitly set it.

Once your repository is set, you can view the servers that are available:

mylist = Meta Get Servers();

{"SASMain", "Schroedl", "SASMain_ja", "SASMain_zh", "SASMain_ko", "SASMain_fr", "SASMain_de", "SASMain_Unicode"}

Next, set your SAS connection. You can also use this command to connect directly to a local or remote server instead of using a metadata server.

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.

Automatically Connect SAS Libraries

When you connect to a SAS server, use Connect Libraries to automatically connect metadata-defined libraries.

conn = SAS Connect( "SASMain", Connect Libraries( 1 ) );

All metadata-defined libraries are connected, which can slow down your connection.

To connect specific libraries later, use the SAS Connect Libref() function or Connect Libref message to a SAS server object.

View SAS Libraries

After you connect to a SAS server, use the Get Lib Ref() function 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"}

If the library containing the data that you want is not assigned, assign it:

conn << Assign Lib Refs( "MyLib", "$DOCUMENTS/data" );

Open SAS Data Sets

First, assign a SAS library reference:

conn << Assign Lib Refs( "MyLib", "$DOCUMENTS" );

The first argument is any name that you want to use to refer to the library reference. The second is the path on the server where the data sets are located.

Next, get the list of data sets in the selected library:

datasets << Get Data Sets( "MyLib" );

{"ANDORRA", "ANDORRA2", "ANYVARNAME", "BOOKS", "BOOKSCOPYNOT", "BOOKS_VIEW", "CATEGORIES", "DATETIMETESTS", "MOREUGLY", "NOTTOOUGLY", "PAYPERVIEW", "PUBLISHERS", "PURCHASES", "PURCHASES_FULL",

Now you can open a data set:

conn << Import Data( "MyLib", "PURCHASES" );

or

conn << Import Data( librefs[1], datasets[12] );

or

conn << Import Data( "MyLib.PURCHASES" );

Now you can get information about any SAS data set in that library. For example, you can get a list of variables:

conn << Get Var Names( "MyLib.PURCHASES" );

{"purchaseyear", "purchasemonth", "purchaseday", "bookid", "catid",

"pubid", "price", "cost"}

With that information, you can choose to import only part of the data set by specifying the variables to import.

conn << Import Data( librefs[1], datasets[12], columns( bookvars[1], bookvars[2], bookvars[4] ) );

Note: The name specified in Import Data can be a friendly metadata library name or a SAS 8-character library name.

Save SAS Data Sets

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 );

Run a Stored Process

To get a reference to a stored process:

stp = Meta Get Stored Process( "Samples/Stored Processes/Sample: Hello World" );

There is no way to acquire a list of stored processes through JSL; you must know the path to the stored process that you want to run.

To run it, send the stored process a message:

stp << Run();

Submit SAS Code from JMP

You can also directly submit SAS code and get back SAS results. For example:

conn << Submit( "proc print data=sashelp.class; run;" );

Two optional arguments control whether you see the output and the SAS log in JMP:

conn << Submit( "SAS Code" <,No Output Window(True|False)> <,Get Log(True|False )> );

You can also see the SAS Log at any time using the command

conn << Get Log();

Get Log() returns the contents, which can be placed in a JSL variable and used like any JSL string.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).
.