11月 122018
 

The SGPLOT procedure enables you to use the value of a response variable to color markers or areas in a graph. For example, you can use the COLORRESPONSE= option to define a variable whose values will be used to color markers in a scatter plot or cells in a heat map. You can use the COLORMODEL= statement to use a pre-defined color ramp or to define and use a custom color ramp. These options are often used to visualize a "third variable" (Z) in a two-dimensional plot (Y vs X).

However, the SGPLOT procedure is not the only way to create color ramps. Recently, I needed to create a custom color ramp and specify a color for values that were outside of a certain range. I also needed to change the color used for missing values in the response variable. This article shows how to perform these tasks by using the RANGEATTRMAP statement in the SAS Graph Template Language (GTL).

Create a basic color ramp in SAS

SAS provides several ways to visualize the values of a response variable in scatter plots, contour plots, heat maps, and other graphs. An example is shown to the right. In this scatter plot, the markers represent data for patients in a heart study. The two-dimensional coordinates of the markers represent the systolic blood pressure and the MRW ratio (a body-mass index) of 80 patients. The colors indicate measurements of cholesterol. Three observations are highlighted by using arrows. One point has an extreme value of cholesterol (400). Two others have missing values of cholesterol and are shown in a grey color by default.

The code that generates the graph follows. The COLORRESPONSE= option is used to name the response variable. The values of the response variable determine the color for each marker according to the color ramp that is specified on the COLORMODEL= option.

data Have;           /* example data: a subset of the Heart data set */
set Sashelp.Heart(firstobs=5000 rename=(Systolic=X MRW=Y Cholesterol=Z)
                  where=(X < 200 AND Y < 200));
label X="Systolic" Z="Cholesterol";
keep X Y Z;
run;
 
title "Markers Colored by Using the COLORRESPONSE= Option";
proc sgplot data=Have;
   scatter x=X y=Y / colorresponse=Z                 /* specify response variable */
                     colormodel=ThreeAltColorRamp    /* specify color ramp */
                     filledoutlinedmarkers markerattrs=(symbol=CircleFilled size=12);
   xaxis grid; yaxis grid;
run;

Advanced features for custom color ramps

The SGPLOT option provide basic functionality for creating a custom color ramp. For more control, you can use either of the following advanced techniques:

The RANGEATTRMAP statement

As shown in the previous example, using a color ramp requires that you specify two pieces of information: a response variable and a color ramp. In GTL, use the RANGEATTRVAR statement to specify the response variable. Use the RANGEATTRMAP statement to define a custom color ramp.

Although the documentation discusses it, I was initially confused about the difference between color ramps and "alt" color ramps. I erroneously assumed that they are functionally equivalent. After all, when I use the COLORMODEL= option in PROC SGPLOT, I can choose any predefined color ramp. For example, the graph at the start of this article is created by using COLORMODEL=ThreeAltColorRamp, which is a blue-black-red color ramp. However, I could just as easily specify COLORMODEL=ThreeColorRamp to use a blue-white-red color ramp.

However, in the RANGEATTRMAP statement, there is a substantive difference between the RANGECOLOR= option and the RANGEALTCOLOR= option:

  • Use the RANGECOLOR= and RANGECOLORMODEL= options to define a color ramp for "area plots" that use a fill color, such as bar charts, histograms, mosaic plots, heat maps, and contour plots. Sanjay's example of a heat map and my example of a mosaic plot are both "area plots" that use the RANGECOLORMODEL= option.
  • Use the RANGEALTCOLOR= and RANGEALTCOLORMODEL= options to define a color ramp for graphs that use lines and markers, such as scatter plots and series plots. The documentation for the RANGEATTRMAP statement provides an example of a scatter plot whose markers are colored according to a range attribute map.

The following GTL defines a template that creates a scatter plot that is similar to the one at the beginning of this article. Because I want to color markers, I use the RANGEALTCOLOR= and RANGEALTCOLORMODEL= options. The RANGEATTRMAP statement contains three RANGE statements. Each RANGE statement associates a color or colors with ranges of data values:

  • A custom yellow-orange-red color ramp is used for cholesterol values less than 350.
  • A custom color (black) is used for markers whose Z-value is greater than 350.
  • A custom color (lime green) is used for markers whose Z-value is missing.
proc template;
define statgraph scatter3Dcol;
begingraph;
   rangeattrmap name="ResponseRange";
        range min-350 / rangeAltColorModel=(CXFFFFB2 CXFED976 CXFEB24C CXFD8D3C CXFC4E2A CXE31A1C CXB10026);
        range OTHER   / rangeAltColor=Black;   /* or use the OVER or UNDER keyword */
        range MISSING / rangeAltColor=Lime;    /* color for missing values */
   endrangeattrmap;
   rangeattrvar var=Z                          /* specify response variable in data set */
                attrmap="ResponseRange"        /* specify custom color ramp */
                attrvar=RangeVar;              /* alias for this variable/ramp combination */
 
   entrytitle "Markers Colored by Using the RANGEATTRMAP Statement";
   layout overlay;
      scatterplot x=X y=Y / markercolorgradient=RangeVar  /* color by Z and custom color ramp */
                  filledoutlinedmarkers=true
                  markerattrs=(symbol=circlefilled size=12) 
                  name="Scatter";
      continuouslegend "Scatter" / title='Cholesterol'; 
   endlayout;
endgraph;
end;
run;
 
proc sgrender data=Have template=scatter3Dcol;
run;

You can do more with the RANGEATTRMAP statement, but I'll stop here. In summary, you can use the RANGEATTRMAP (and RANGEATTRVAR) statement in the Graph Template Language to define a custom color ramp. The RANGEATTRMAP statement supports features that are not surfaced in PROC SGPLOT, such as enabling you to specify a color for out-of-range values and missing values. If you are going to use the color ramp in an "area plot" such as a heat map, use the RANGECOLOR= and RANGECOLORMODEL= options to define the color ramp. If you are going to use the color ramp to color lines and markers, use the RANGEALTCOLOR= and RANGEALTCOLORMODEL= options.

The post Define custom color ramps by using the RANGEATTRMAP statement in GTL appeared first on The DO Loop.

11月 102018
 

"The customer is always right," was popularized by pioneering, successful retailers such as Harry Gordon Selfridge, John Wanamaker and Marshall Field. I remember a variation on this idea — Rule 1. The customer is always right. Rule 2. If the customer is wrong, go back to Rule 1.

This fundamental premise of customer service remains true regardless of channel: brick-and-mortar store, mobile device or website.

Emerging technologies provide retailers the opportunity to differentiate themselves with data and analytics that enhance the customer experience. Retailers can partner with the analytics using data associated with past and present interactions and through systemic innovation can capitalize on future customer interactions.

SAS has been a Red Hat partner for more than 15 years. Its retail customers use Red Hat technologies across many parts of their organizations. Red Hat Enterprise Linux is the preferred choice for many SAS retail customers because it provides a stable, reliable platform with a low total cost of ownership. SAS® Analytics, when paired with Red Hat Middleware, allows teams to seamlessly integrate retail data movement from the edge to the data center. In addition, both companies have developed a joint workflow to ensure that customer problems are resolved quickly.

But what does this partnership really mean to the retail customer?

Four factors that make retail analytics real

Better scalability. Seasonal factors can significantly impact the retail industry. A spike in demand around signature events -- planned and unplanned – can result in order-of-magnitude variations in the volume of data to be processed. The larger the data volume, the higher the compute and storage resources required.

That’s where cloud can come in. SAS Analytics with Red Hat open cloud technology allows retailers to scale their analytics up and out as their business climate evolves by automatically provisioning additional resources.

Faster time to analytics. The digital customer is not only motivated by the products available through the retailer but also to the overall shopping experience. A robust IT strategy has become even more important to the retailer.

Retailers need to continually develop new features that draw customers to the store for the experience. The goal is to entice a digitally-minded customer to get offline and come to the store. Red Hat solutions power DevOps implementations that speed time to market.

Increased flexibility. The digital world would be a lot simpler if everyone a single cloud solution. But it is a hybrid world out there with a multitude of workloads that are best suited for a diverse array of environments including bare metal, virtual machines, private and public clouds.

Workloads may need to be moved across these environments as well. Red Hat technologies allow retailers to virtualize their SAS analytics over a range of secure deployment options, including public, private, and hybrid clouds.

Added security. Data being such a precious commodity, digital retailers may have to be more concerned in some cases about the security and privacy of their customer’s data than the goods they sell! ‘Adversaries R Us’ are always on the prowl in the digital neighborhood, continuously innovating newer ways to penetrate the enterprise to access the customer data.

Prevention is better than cure, even when it comes to data security. With the SAS and Red Hat platform, customers benefit from continuous built-in security, offered end-to-end on trusted platforms and augmented by automated patching and proactive remediation in compliance with regulatory standards.

There you have it!

SAS and Red Hat provide a platform that supports every phase of the analytics life cycle to ensure that the Customer will always be right! Let me take it a step further. If such partnerships are not leveraged to benefit the customer, Retailers will be proven wrong!

How else can they drive a partnership with analytics?

The customer will always be right with open analytics was published on SAS Users.

11月 092018
 

In parts one and two of this blog posting series, we introduced machine learning models and the complexity that comes along with their extraordinary predictive abilities. Following this, we defined interpretability within machine learning, made the case for why we need it, and where it applies. In part three of [...]

SAS Customer Intelligence 360: A look inside the black box of machine learning [Part 3] was published on Customer Intelligence Blog.

11月 092018
 

In parts one and two of this blog posting series, we introduced machine learning models and the complexity that comes along with their extraordinary predictive abilities. Following this, we defined interpretability within machine learning, made the case for why we need it, and where it applies. In part three of [...]

SAS Customer Intelligence 360: A look inside the black box of machine learning [Part 3] was published on Customer Intelligence Blog.

11月 092018
 

With the recent midterm elections here in the US, I frequently saw congressional district maps popping up in the news. And being a GraphGuy, I wanted to fully understand these maps, to see if I might could improve them. If you're interested in congressional district maps, follow along as I [...]

The post Enhancing a congressional district map - one layer at a time appeared first on SAS Learning Post.

11月 072018
 

How different is different? Descriptive analytics is powerful. You get to see your data and seeing is believing as they say. But blindly believing what you see is not always the best strategy. Asking someone else if they see what you see helps but is still subjective. Objectivity starts with [...]

Segment comparisons – Seeing is believing but measuring is knowing was published on Customer Intelligence Blog.

11月 072018
 

Migration, version road maps and configurations were the themes of several questions that came up in a recent webinar about combining SAS Grid Manager and SAS Viya. You’ll see in this blog post that we were ready to get into the nitty-gritty details in our answers below – just as we did in the previous FAQs post. We hope you find them useful in your work using SAS Grid Manager and SAS Viya together.

1. Can we migrate SAS programs that are currently on SAS PC environments into the SAS Grid environment – or do we need to rewrite the programs for SAS Grid Manager?

No, you don’t need to rewrite your SAS programs to run on a SAS Grid environment. Many customers migrate their code from other environments (like PCs or servers) and submit them to SAS Grid Manager from SAS Display Manager, SAS Studio or any other application of their choice.

If you already use SAS Enterprise Guide to run jobs on a remote server, the process may be as simple as changing your server configuration to use a grid-launched workspace server (information that your SAS Administrator would provide) and continuing to work in much the same way as always, requiring no changes to your code.

Depending on other changes that take place at the same time SAS Grid Manager is implemented, there may need to be some small adjustments to your programs.  For example, if your organization consolidates source data onto new storage, you may need to change paths associated with your LIBNAME statements.  These should be housekeeping items rather than significant rewrites of the logic in your SAS code.

If you plan to continue to use the programming environment provided by BASE SAS itself (DMS) and have been using SAS/CONNECT, you will need to add the SIGNON statement to start a session on the SAS Grid Manager

  • ENDRSUBMIT statement to end the block of code to be run on the grid
  • Divide and Conquer – Writing Parallel SAS Code to Speed Up Your SAS Program.

    2. Is there a version of SAS Grid Manager that runs on the SAS Viya architecture?

    The SAS Grid Manager roadmap includes a release of SAS Grid Manager on the SAS Viya Architecture late in 2019.

    3. Will I be able to migrate my SAS Grid Manager configuration and jobs from SAS 9.4 to the SAS Viya-based release of SAS Grid Manager?

     The plan to deliver SAS Grid Manager on the SAS Viya architecture includes automation to migrate jobs, flows, and schedule information from your SAS 9.4 environment to your SAS Viya environment.  It is our goal to make this transition as straightforward and easy as possible – especially where there is feature parity between SAS 9 based and SAS Viya-based solutions.  Since each product delivers solution-specific PROCs and other functionality that can be used within a job executed by SAS Grid Manager, each customer should work with their SAS team to understand which jobs can be migrated and which jobs may need to continue to run against your SAS 9.4 environment.  

    * * *

    These were all great questions that we thought deserved more detail than we could offer in a webinar.  If you have more questions that weren’t covered here, or in our previous post on this topic, just post them in the comments section.  We’ll answer them quickly.  Thanks for your interest!

    3 questions about implementing SAS Grid Manager and SAS Viya was published on SAS Users.