Skip to content
Shane Rosanbalm edited this page Sep 12, 2019 · 21 revisions

Contents

  1. Introduction
  2. Version Requirements
  3. Macro Parameters
  4. Macro Behavior
  5. Examples
  6. Sample SAS Programs
  7. Customization

Introduction

There is no built-in statement for producing a parallel coordinates plot in SAS. This wiki describes the %parallelplot macro, which was designed to generate nice-looking parallel coordinates plots in SAS with a minimum of effort.

%parallelplot
   (data=sashelp.iris
   ,var=sepallength sepalwidth petallength petalwidth
   ,group=species
   );

parallel percentiles

Version Requirements

Short version: You need 9.4m2 or higher to run this macro.

Long version: This macro uses features from 9.4m0 (text statement and noborder option) and 9.4m2 (series option grouplc= and keylegend option type=linecolor). The text statement is used when axistype=datavalues is specified. The grouplc= and type=linecolor options are used when group= is specified. Those running versions prior to 9.4 could possibly rewrite these sections of the macro to be compatible with earlier SAS versions, though it would get a bit messy.

Macro Parameters

Parameter Description
data= Input dataset.
Required.
var= Space-separated list of variables to plot.
Required.
Specifying var=_numeric_ will include all numeric variables.
group= A grouping variable.
Optional.
If no grouping variable is specified, all lines will be the same color.
axistype= Type of yaxis to create.
Optional.
Valid values: percentiles,datavalues.
Default: percentiles.
sgplotout= Full file path in which to save SGPLOT code.
E.g., sgplotout=C:/temp/myparallel.sas.

Macro Behavior

  • The macro requires that the variables in the var= list are numeric.
    • The variables are arranged from left to right with equal spacing along the x2axis.
    • The variable labels are used as tick values.
  • If a group= variable is specified, a legend will be produced with color coding for each value of the group= variables.
  • By default, all variables are standardized on a [0,1] scale.
    • If axistype=datavalues is used, the macro generates "nice" tick values for all variables and overlays them on the plot.
  • The SGPLOT code generated by the macro can be captured (and modified) using the sgplotout= parameter (see Customization below).

Examples

Example 1: required parameters only.

%parallelplot
   (data=sashelp.iris
   ,var=sepallength sepalwidth petallength petalwidth
   );

parallel sans by

Example 2: adding a group= variable.

%parallelplot
   (data=sashelp.iris
   ,var=sepallength sepalwidth petallength petalwidth
   ,group=species
   );

parallel percentiles

Example 3: changing to axistype=datavalues.

%parallelplot
   (data=sashelp.iris
   ,var=sepallength sepalwidth petallength petalwidth
   ,grouop=species
   ,axistype=datavalues
   );

parallel datavalues

Note: when you specify axistype=datavalues, the "nice" tick values are generated using a macro called %axisorder.

Example 4: lots of variables.

data cars;
   set sashelp.cars;
   label
      horsepower = "Horsepower"
      msrp = "MSRP ($)"
      invoice = "Invoice ($)"
      ;
run;

%parallelplot
   (data=cars
   ,var=enginesize horsepower msrp invoice weight length mpg_city mpg_highway wheelbase
   ,group=origin
   ,axistype=datavalues
   );

parallel datavalues

Note: In the above example a label statement was used prior to the macro call to add labels to variables that did not have them in the source data. This labeling step is optional. If a variable does not have a label the tick value will default to the variable name.

Sample SAS Programs

Are available here.

Customization

The %parallelplot macro would quickly become unmanageable if we were to try to add optional parameters for every cosmetic detail a user is likely to want to adjust (line color/pattern/thickness, font family/size/weight, etc.). Rather than create an unmanageable macro, we instead leave it to the user who is unsatisfied with the cosmetics of the resulting plot to use sgplotout= to capture the code produced by the macro and edit away on the back end.

*--- call the macro, but disregard the resulting image ---;

ods listing gpath="_some_temp_folder_";
ods graphics / imagename="junk";

%parallelplot
   (data=sashelp.iris
   ,var=sepallength sepalwidth petallength petalwidth
   ,group=species
   ,sgplotout=C:/temp/myparallel.sas
   );

*--- copy the code from myparallel.sas into your program and edit away ---;

ods listing gpath="_permanent_folder_";
ods graphics / imagename="treasure";

/* begin copied code */
proc sgplot ...;
   styleattrs ...;
   series ...;
   text ...;
   x2axis ...;
   yaxis ...;
   y2axis ...;
   keylegend ...;
run;
/* end copied code */

Note: the call to %parallelplot needs to be retained even after the sgplot code has been copied into the program as the macro call is what creates the work dataset used by SGPLOT.