BookmarkSubscribeRSS Feed

Using the SAS-ArcGIS Bridge: What to Know

Started ‎09-01-2023 by
Modified ‎09-01-2023 by
Views 571

Export as CSV. Import. Load table. Save. If you’ve ever worked on a project that involved multiple analytical platforms, you may have resorted to those exact steps while trying to figure out the best way to move data back and forth between locations. However, if your workflow involves using both SAS and ArcGIS Pro, you don’t need to worry about this!

 

ArcGIS Pro is a GIS (geographic information system) software developed by Esri. It is widely used by geospatial professional to create, manage, manipulate, and visualize spatial data. The SAS-ArcGIS Bridge, a partnership between Esri and SAS, includes two key features: the ability to move data back and forth between ArcGIS Pro and SAS Viya, and the ability to run SAS code directly within ArcGIS Pro. I’ll discuss both of these in detail in this post.

 

Requirements

 

In order to use these features, you must have access to ArcGIS Pro 2.9 or later, your CAS server must be configured to allow external connections (such as using the SWAT package), and you must know the CAS connection information (the host and port, and an authorization method).

 

The SAS Toolset

 

In ArcGIS Pro, geoprocessing tools are grouped together in toolboxes.

 

Edited_01_treiman_gis_2.png

Select any image to see a larger version.

Mobile users: If you do not see this image, scroll to the bottom of the page and select the "Full" version of this post.

 

There is a Conversion toolbox that contains a number of tools that allow you to easily convert data back and forth between different formats. One of the toolsets in that toolbox is called the SAS Toolset, and it allows you to move data back and forth between ArcGIS Pro and SAS Viya. This means that you can take an Esri table and load it to memory in CAS, or take a CAS table in memory and view it in ArcGIS. The integrity of your data is maintained in both directions: lengths, types, labels, and other attributes are respected in a way that makes sense on both platforms.

 

Let’s look at an example.

 

Note: For more information about getting started with ArcGIS Pro, Esri provides a set of quick-start tutorials.

 

Converting an SAS dataset to an Esri table

 

In the SAS Toolset, there are two tools: SAS to Table and Table to SAS.

 

Edited_02_treiman_gis_3-1.png

 

The SAS to Table to tool converts a SAS dataset to an Esri table, and the Table to SAS tool converts an Esri table to a SAS dataset.

 

The tool uses a point-and-click interface. First, you must specify the name and library of the input SAS dataset and the name of the Esri table to create. ArcGIS Pro can access both datasets in a local SAS 9 installation, and CAS tables in SAS Viya. CAS tables must be loaded to memory.

 

In order to access a CAS table, you must also check the Download SAS Dataset from SAS Cloud Analytic Services (CAS) option. Clicking this add additional fields to specify how to connect to CAS. You must provide the CAS Hostname URL and Port of your environment, and you must also authenticate to CAS, either by providing a CAS Authorization File, or by specifying your CAS username and password.

 

In this example, I want to convert a CAS table called OK_POST_LOC in the PUBLIC caslib to an Esri table. This table contains latitude and longitude coordinates for post office locations in the state of Oklahoma, and I want to convert it to an Esri dataset to take advantage of ArcGIS’s spatial visualization capabilities. I’ve provided the connection information for my deployment of SAS Viya and supplied my credentials to authenticate to CAS.

 

Edited_03_treiman_gis_5.png

 

Once the tool has finished running, the new table will appear in the content pane on the left-hand side of the window.

 

Edited_04_treiman_gis_6.png

 

Once a SAS dataset has been converted to an Esri table in ArcGIS Pro, I can open it and examine the attribute table:

 

Edited_05_treiman_gis_7.png

 

Or I can use one of the many other geoprocessing tools available in ArcGIS Pro to create a spatial visualization, such as the XY Table to Point tool:

 

Edited_06_treiman_gis_8.png

 

 

Converting an Esri table to a SAS dataset

 

The Table to SAS tool takes an Esri table as an input and creates a SAS table. Like the reverse, it can create both a .sas7bdat dataset in a local SAS 9 installation, and it can create an in-memory CAS table in SAS Viya.

 

The parameters for the Table to SAS tool are very similar to the parameters for the SAS to Table tool. You must specify the input table in ArcGIS Pro, which can be either a stand-alone table or the attribute table of a feature class, and library and table name of the SAS table you want to create. Like before, you also need to choose whether to upload the table to CAS or not. If you do, you’ll need to provide the same CAS connection and authentication information. You can also select whether you’d like to replace the dataset if it already exists.

 

In this example, I want to convert a feature class containing population information for counties in North Carolina to a CAS table so I can do additional analytics and processing. I’ve selected the attribute table of the feature class as the input table, and I’m creating a CAS table called NC_COUNTY in the PUBLIC caslib. I’ve provided the connection information for my deployment of SAS Viya and supplied my credentials to authenticate to CAS.

 

Edited_07_treiman_gis_9.png

 

Once I’ve run the Table to SAS tool, I can confirm that the new table appears in SAS Viya:

 

Edited_08_treiman_gis_10.png

 

Note: Both the Table to SAS and the SAS to Table can also be scripted in Python using the ArcPy package.

 

Running SAS code from ArcGIS Pro

 

Once you have converted an Esri table to a SAS dataset, you can then interact with it and analyze it using SAS code, directly from ArcGIS Pro, using the built-in Python editor. There are two ways to do this. If you are working with a local installation of SAS 9, you can use the SASPy package. If you are using SAS Viya, you can use the SWAT package to connect to CAS and use CAS actions analyze your data.

 

To run SAS code in ArcGIS, I’ll start by creating a Python notebook. The first step to accessing data in CAS is to import the SWAT package and create a CAS connection. I can do so with the following code (Note that you will need to supply your own CAS credentials or other authorization method):

 

import swat
conn = swat.CAS("server.demo.sas.com", 30570, 'christine', 'Student1')

 

Note: For demonstration purposes, I’ve put my authentication information in plain text. In the real world, never do this! Instead, use an authinfo file, set up Python environment variables, or use a hashed version.

 

Once you’ve connected to CAS, you can use all of the different CAS actions available as part of the SWAT package to manipulate and analyze your data.

 

For example, I can reference the table I converted from Esri in the last section and store it in a variable called tbl with the following code:

 

tbl = conn.CASTable('nc_county', caslib = 'public')

Then, I can use the Summary action from the Simple action set to calculate summary statistics about my CAS table:

 

tbl.simple.summary()

Edited_09_treiman_gis_11.png

 

Notice the syntax used to call CAS actions with the SWAT package: object.CAS-Action-Set.CAS-Action. It isn’t necessary to qualify the CAS action with the action set name, but it is a good practice.

 

Finally, I can also run regular, CAS-enabled DATA step code using the SWAT package. For example, I can run the following code to filter my CAS table and calculate a new column:

 

conn.runcode(code = '''
    data public.nc_pop_centers;
        set public.nc_county;
        where Total > 100000;
        Pop_Density = Total/Land_km;
    run;
''')

 

For more information about all of the powerful ways to use the SWAT package to manipulate CAS data using Python, see Peter Styliadis’ blog series on the topic.

 

Conclusion

 

ArcGIS Pro is a commonly used tool by geospatial professionals in a wide variety of industries. Thanks to the SAS-ArcGIS Bridge, it’s possible for ArcGIS users to quickly and easily perform robust analysis using SAS code, and it’s possible for SAS users to move data quickly and easily to ArcGIS to create visualizations and perform advanced spatial analysis.

 

 

Find more articles from SAS Global Enablement and Learning here.

Version history
Last update:
‎09-01-2023 09:08 AM
Updated by:
Contributors

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Tags