BookmarkSubscribeRSS Feed

SAS Data Studio 2.2: Use the Code Transform to Rearrange Fields for the Results Table

Started ‎09-13-2018 by
Modified ‎09-13-2018 by
Views 2,153

SAS Data Studio 2.2 powered by SAS Viya 3.4 provides a mechanism for performing simple, self-service data preparation tasks to prepare data for use in SAS Visual Analytics or other applications. It is accessed via the Prepare Data menu item from SAS Drive. Note: A user must belong to the Data Builders custom group to have access to this menu item.

 

I have had several people ask during training classes, how they can control the column order and names for their saved tables resulting from a data plan in SAS Data Studio. The best way to do this is to use the Code Transform in Data Studio to write custom code to create custom code to perform actions or transformations on a table. In previous posts, I have explored some uses of the Code Transform. In this article, I will show how you can use the Code Transform to rearrange the fields on the results table by writing CASL code using the action set fedSQL. For more information on the fedSQL action set, refer to the documentation.

 

In my Data Studio plan, my current results table after doing all my desired transformations to the source table is:

 

1_ResultsTableBefore.png

click on images to see a larger version

 

However, I want my results table to look like this:

 

2_ResultsTableAfter.png

 

In order to achieve this desired result, I write the following CASL code using the fedSQL action set in a Code transform in my Data Studio plan.

 

3_FedSQLCodeRearrange.png

 

This code keeps only the desired columns: Team, Name_GivenName_Parse, Name_FamilyName_Parse, YrMajor, nAtBat, and nHits. It also renames the Name_GivenName_Parse and Name_FamilyName_Parse columns to First Name and Last Name respectively as well as rearranges the columns into the desired order.

 

Now, when I run and save the plan and create its resulting table, the following table is saved with only the desired column names and the specified order.

 

4_SavedResultsTable.png

 

 

For more information on SAS Data Studio 2.2 powered by SAS Viya 3.4, you can refer to the documentation for SAS Data Studio 2.2: User's Guide.

Version history
Last update:
‎09-13-2018 08:47 AM
Updated by:
Contributors

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

SAS AI and Machine Learning Courses

The rapid growth of AI technologies is driving an AI skills gap and demand for AI talent. Ready to grow your AI literacy? SAS offers free ways to get started for beginners, business leaders, and analytics professionals of all skill levels. Your future self will thank you.

Get started

Article Tags