ods graphics

142017
 

This post is part of our SAS Author Tips series. Today's post is from SAS Author Sanjay Matange. Do you have a complex multi-cell graph created in ODS Graphics Designer that you’d like to reuse with different data? Ideally, you’d like to change the data without having to change the plots in each [...]

The post Reuse a Graph with Different Data appeared first on SAS Learning Post.

十一 022016
 

Fun with ODS GraphicsSAS Community member @tc (a.k.a. Ted Conway) has found a new toy: ODS Graphics. Using PROC SGPLOT and GTL (Graph Template Language), along with some creative data prep steps, Ted has created several fun examples that show off what you can do with a bit of creativity, some math knowledge, and open data.

And bonus -- since most of his examples work with SAS University Edition, it's easy for you to try them yourself. Here are some of my favorites.

Learn to draw a Jack-O-Lantern

Using the GIF output device and free data from Math-Aids.com, Ted shows how to use GTL (PROC TEMPLATE and PROC SGRENDER) to animate this Halloween icon.

learn to draw a Jack-O-Lantern

The United Polygons of America

Usually map charts with SAS require specialized procedures and map data, but here's a technique that can plot a stylized version of the USA and convey some interesting data. (You might have seen this one featured in a SAS Tech Report newsletter. Do you subscribe?)

United Polygons of America

A look at Katie Ledecky's dominance

Using a vector plot, Ted shows how this championship swimmer dominated her event during the summer games in Rio. This example contains a lot of text information too; and that's a cool trick in PROC SGPLOT with the AXISTABLE statement. Click on the image for a closer look.

Katie Ledecky dominates

Demonstrating the Bublé Sort

This example is nerdy on so many levels. It's a take on the Computer Science 101 concept of "bubble sort," an algorithm for placing a collection of items in a desired order. In this case, the items consist of Christmas songs recorded by Michael Bublé, that dreamy crooner from Canada.

See the songs sort things out
Ted posts these examples (and more) in the SAS/GRAPH and ODS Graphics section of SAS Support Communities. That's a great place to learn SAS graphing techniques, from simple to advanced, and to see what other practitioners are doing. Experts like Ted hang out there, and the SAS visualization developers often post answers to the tricky questions.

More from @tc

In addition to his community posts, Ted is an award-winning contributor to SAS Global Forum with some very popular presentations. Here are a few of his papers.

tags: ODS Graphics, SAS Communities, SGPLOT

The post Binge on this series: Fun with ODS Graphics appeared first on The SAS Dummy.

132015
 

cbhat_sgRick Wicklin created a nice example of using the SURFACEPLOTPARM statement to create a surface plot in SAS. As I read it, the question that immediately came to mind was: can I use this to create the famous SAS cowboy hat?

The "cowboy hat" is a highly distributed example of using PROC G3D to create a 3-dimensional rendering of data that resembles...well...a cowboy hat. PROC G3D is a cool SAS proc, but it's part of the SAS/GRAPH product and not everyone has access to that. For example, users of the SAS University Edition cannot run PROC G3D or any SAS/GRAPH programs. But the SG procedures, including SGPLOT and SGRENDER, are built into Base SAS.

Now we can bring the cowboy hat to the next generation of SAS users. Without further ado, here is the SAS program that build the hat. The program works in SAS Display Manager, SAS Enterprise Guide, and SAS University Edition.

/* Graph Template Language that defines the graph layout    */
/* This needs to be run just once within your SAS session   */
/* From Rick's post at:                                     */
/* http://blogs.sas.com/content/iml/create-surface-plot-sas */
proc template;                        /* surface plot with continuous color ramp */
define statgraph SurfaceTmplt;
dynamic _X _Y _Z _Title;              /* dynamic variables */
 begingraph;
 entrytitle _Title;                   /* specify title at run time (optional) */
  layout overlay3d;
    surfaceplotparm x=_X y=_Y z=_Z /  /* specify variables at run time */
       name="surface" 
       surfacetype=fill
       colormodel=threecolorramp      /* or =twocolorramp */
       colorresponse=_Z;
    continuouslegend "surface";
  endlayout;
endgraph;
end;
run;
 
/* DATA step to create the "hat" data */
data hat; 
 do x = -5 to 5 by .5;
  do y = -5 to 5 by .5;
   z = sin(sqrt(y*y + x*x));
   output;
  end;
 end;
run;	
 
ods graphics / width=1000 height=800;
 
/* And... Render the Hat! */
proc sgrender data=hat template=SurfaceTmplt; 
   dynamic _X='X' _Y='Y' _Z='Z' _Title="Howdy Pardner!";
run;
tags: ODS Graphics

The post The famous SAS cowboy hat now fits all SAS users appeared first on The SAS Dummy.

302015
 

SAS Global Forum logoODS Graphics is not exactly new.  It became production with SAS 9.2 back around 2008, and before then it existed in a pre-production form at least as early as 2003.  So you would think that by now everyone who uses SAS would be using ODS Graphics, but apparently this is not the case.

It has come to my attention that some long-time SAS users still use PROC CHART–not even PROC GCHART, but PROC CHART which was designed for line printers back in the 1970s and creates graphs using alphanumeric characters!  Here is an example of a bar chart created using PROC CHART:

PROC_CHART

There is no excuse for this (unless, of course, you are trying to create a hip, retro vibe).  ODS Graphics is easy to use and produces beautiful graphs.  Here is the same bar chart created using PROC SGPLOT:

PROC_SGPLOT

Now, if you are one of those people who uses SAS/Graph and PROC GCHART, and you are able to get the results you want, then that’s great.  I would never tell a SAS/Graph user to switch to ODS Graphics.  But for most people SAS/Graph is just too hard to use.  That’s why the developers at SAS created ODS Graphics: for the rest of us.  Just to prove that PROC SGPLOT is not any harder than PROC CHART, here is the code I used to create the two preceding bar charts:

PROC CHART DATA = olympics;
VBAR Region / SUBGROUP = PopGroup;
RUN;

PROC SGPLOT DATA = olympics;
VBAR Region / GROUP = PopGroup;
RUN;

If you are one of those people who still hasn’t learned ODS Graphics (or if you are new to SAS and want to get off on the right foot), this is your big chance.  At the recent SAS Global Forum conference, Lora Delwiche and I presented our paper “Graphing Made Easy with SGPLOT and SGPANEL Procedures.”  You can view that presentation.  Give us 50 minutes of your time, and we will convince you that ODS Graphics is easy (and maybe even fun) to use.  We start with a general introduction so you understand how the SGPLOT and SGPANEL procedures fit into the larger world of ODS Graphics, then we show how to create different types of graphs and how to customize them.

To watch our presentation, click here.

To download a copy of our paper, click here.

A lot of other great presentations were recorded at SGF too.  To see the full list, click here.

Happy graphing!

 


302015
 

SAS Global Forum logoODS Graphics is not exactly new.  It became production with SAS 9.2 back around 2008, and before then it existed in a pre-production form at least as early as 2003.  So you would think that by now everyone who uses SAS would be using ODS Graphics, but apparently this is not the case.

It has come to my attention that some long-time SAS users still use PROC CHART–not even PROC GCHART, but PROC CHART which was designed for line printers back in the 1970s and creates graphs using alphanumeric characters!  Here is an example of a bar chart created using PROC CHART:

PROC_CHART

There is no excuse for this (unless, of course, you are trying to create a hip, retro vibe).  ODS Graphics is easy to use and produces beautiful graphs.  Here is the same bar chart created using PROC SGPLOT:

PROC_SGPLOT

Now, if you are one of those people who uses SAS/Graph and PROC GCHART, and you are able to get the results you want, then that’s great.  I would never tell a SAS/Graph user to switch to ODS Graphics.  But for most people SAS/Graph is just too hard to use.  That’s why the developers at SAS created ODS Graphics: for the rest of us.  Just to prove that PROC SGPLOT is not any harder than PROC CHART, here is the code I used to create the two preceding bar charts:

PROC CHART DATA = olympics;
VBAR Region / SUBGROUP = PopGroup;
RUN;

PROC SGPLOT DATA = olympics;
VBAR Region / GROUP = PopGroup;
RUN;

If you are one of those people who still hasn’t learned ODS Graphics (or if you are new to SAS and want to get off on the right foot), this is your big chance.  At the recent SAS Global Forum conference, Lora Delwiche and I presented our paper “Graphing Made Easy with SGPLOT and SGPANEL Procedures.”  You can view that presentation.  Give us 50 minutes of your time, and we will convince you that ODS Graphics is easy (and maybe even fun) to use.  We start with a general introduction so you understand how the SGPLOT and SGPANEL procedures fit into the larger world of ODS Graphics, then we show how to create different types of graphs and how to customize them.

To watch our presentation, click here.

To download a copy of our paper, click here.

A lot of other great presentations were recorded at SGF too.  To see the full list, click here.

Happy graphing!

 


132015
 

In recent releases of SAS, you can use Output Delivery System graphics or 'ODS graphics on' to produce nice graphical output for most of the analytic procedures. These default graphs are nice, but when you want your graphs to look "a certain way" SAS also lets you create your own custom graphs! […]

The post Creating your own customized graphs for SAS analytic procedures appeared first on The SAS Training Post.

022014
 

Using PROC SGPLOT for Quick High-Quality GraphsSoon I will travel to San Jose for the Western Users of SAS Software 2014 Educational Forum and Conference.  I’m looking forward to doing a hands-on workshop on one of my favorite topics, ODS Graphics, specifically the PROCs SGPLOT and SGPANEL.  Here is the abstract:

New with SAS 9.2, ODS Graphics introduced a whole new way of generating graphs using SAS.  With just a few lines of code, you can create a wide variety of high-quality graphs.  This workshop shows how to produce several types of graphs using PROC SGPLOT, and how to create paneled graphs by converting PROC SGPLOT to PROC SGPANEL.  This workshop also shows how to send your graphs to different ODS destinations, how to apply ODS styles to your graphs, and how to specify properties of graphs, such as format, name, height, and width.

If you are going to the conference, I hope you will attend my workshop Thursday, September 4, 2014 4:00-6:00pm. If not, then you can download the paper, step-by-step handout, and syntax reference tables.


182014
 
In writing the second edition of SAS Programming in the Pharmaceutical Industry, I knew that I wanted to replace the device-driven SAS/GRAPH figures with the new ODS template-driven graphics procedures. The latest developments in SAS graphics involve the template-driven procedures and tools found in SAS ODS graphics (i.e., ODS Graphics […]
052013
 

Now Appearing at Western Users of SAS Software 2013Here is another presentation to which I have contributed for the Western Users of SAS Software 2013 conference.

Your Resume–Selling Yourself Using SAS

I am honored to have served as a co-author with Rebecca Ottesen on this highly original paper.  This paper shows how to use your SAS skills to create a resume that is clever, unique, and effective.

Here is an excerpt:

Your resume should demonstrate strengths and skills, cite meaningful performance metrics, quantify contributions to the organization, and set you apart from the competition, all while being concise and staying to the point.  As a SAS user, it is likely that the skill set you would like to showcase involves programming and data analysis, so it seems perfectly natural that you should use these skills to create content for your resume.  A well thought out SAS graphic or table might be the perfect selling point to catch the attention of a hiring manager.

Here is an example of a graphic showing a timeline for work and academic experience:

Your Resume

If you are at the conference, I hope you will attend our presentation Wednesday November 13, 2013 2:30-2:50pm. If not, then you can download the paper here.


132013
 

If you've watched any of the demos for SAS Visual Analytics (or even tried it yourself!), you have probably seen this nifty exploration of multiple measures.

It's a way to look at how multiple measures are correlated with one another, using a diagonal heat map chart. The "stronger" the color you see in the matrix, the stronger the correlation.

You might have wondered (as I did): can I build a chart like this in Base SAS? The answer is Yes (of course). It won't match the speed and interactivity of SAS Visual Analytics, but you might still find this to be a useful way to explore your data.

The approach

There are four steps to achieving a similar visualization in the 9.3 version of Base SAS. (Remember that ODS Graphics procedures are part of Base SAS in SAS 9.3!)

  1. Use the CORR procedure to create a data set with a correlations matrix. Actually, several SAS procedures can create TYPE=CORR data sets, but I used PROC CORR with Pearson's correlation in my example.
  2. Use DATA step to rearrange the CORR data set to prepare it for rendering in a heat map.
  3. Define the graph "shell" using the Graph Template Language (GTL) and the HEATMAPPARM statement. You've got a lot of control over the graph appearance when you use GTL.
  4. Use the SGRENDER procedure to create the graph by applying the CORR data you prepared in the first two steps.

Here's an example of the result:

The program

I wrapped up the first two steps in a SAS macro. The macro first runs PROC CORR to create the matrix data, then uses DATA step to transform the result for the heat map.

Note: By default, the PROC CORR step will treat all of the numeric variables as measures to correlate. That's not always what you want, especially if your data contains categorical columns that just happen to be numbers. You can use DROP= or KEEP= data set options when using the macro to narrow the set of variables that are analyzed. The examples (near the end of this post) show how that's done.

/* Prepare the correlations coeff matrix: Pearson's r method */
%macro prepCorrData(in=,out=);
  /* Run corr matrix for input data, all numeric vars */
  proc corr data=&in. noprint
    pearson
    outp=work._tmpCorr
    vardef=df
  ;
  run;
 
  /* prep data for heat map */
data &out.;
  keep x y r;
  set work._tmpCorr(where=(_TYPE_="CORR"));
  array v{*} _numeric_;
  x = _NAME_;
  do i = dim(v) to 1 by -1;
    y = vname(v(i));
    r = v(i);
    /* creates a lower triangular matrix */
    if (i<_n_) then
      r=.;
    output;
  end;
run;
 
proc datasets lib=work nolist nowarn;
  delete _tmpcorr;
quit;
%mend;

You have to define the graph "shell" (or template) only once in your program. The template definition can then be reused in as many PROC SGRENDER steps as you want.

This heat map definition uses the fact that correlations are always between -1 and 1. Negative numbers show a negative correlation (ex: cars of higher weight will achieve a lower MPG). It's useful to select a range of colors that make it easier to discern the relationships. In my example, I went for "strong" contrasting colors on the ends with a muted color in the middle.

  /* Create a heat map implementation of a correlation matrix */
ods path work.mystore(update) sashelp.tmplmst(read);
 
proc template;
  define statgraph corrHeatmap;
   dynamic _Title;
    begingraph;
      entrytitle _Title;
      rangeattrmap name='map';
      /* select a series of colors that represent a "diverging"  */
      /* range of values: stronger on the ends, weaker in middle */
      /* Get ideas from http://colorbrewer.org                   */
      range -1 - 1 / rangecolormodel=(cxD8B365 cxF5F5F5 cx5AB4AC);
      endrangeattrmap;
      rangeattrvar var=r attrvar=r attrmap='map';
      layout overlay / 
        xaxisopts=(display=(line ticks tickvalues)) 
        yaxisopts=(display=(line ticks tickvalues));
        heatmapparm x = x y = y colorresponse = r / 
          xbinaxis=false ybinaxis=false
          name = "heatmap" display=all;
        continuouslegend "heatmap" / 
          orient = vertical location = outside title="Pearson Correlation";
      endlayout;
    endgraph;
  end;
run;

You can then use the macro and template together to produce each visualization. Here are some examples:

/* Build the graphs */
ods graphics /height=600 width=800 imagemap;
 
%prepCorrData(in=sashelp.cars,out=cars_r);
proc sgrender data=cars_r template=corrHeatmap;
   dynamic _title="Corr matrix for SASHELP.cars";
run;
 
%prepCorrData(in=sashelp.iris,out=iris_r);
proc sgrender data=iris_r template=corrHeatmap;
   dynamic _title= "Corr matrix for SASHELP.iris";
run;
 
/* example of dropping categorical numerics */
%prepCorrData(
  in=sashelp.pricedata(drop=region date product line),
  out=pricedata_r);
proc sgrender data=pricedata_r template=corrHeatmap;
  dynamic _title="Corr matrix for SASHELP.pricedata";
run;

Download complete program: corrmatrix_gtl.sas for SAS 9.3

Spoiler alert: These steps will only get easier in a future version of SAS 9.4, where similar built-in visualizations are planned for PROC CORR and elsewhere.

Related resources

You can apply a similar "heat-map-style" coloring to ODS tables by creating custom table templates.

If you haven't yet tried SAS Visual Analytics, it's worth a test-drive. Many of the visualizations are inspiring (as this blog post proves).

Finally, while I didn't dissect the GTL heat map definition in detail in this post, you can learn a lot more about GTL from Sanjay Matange and his team at the Graphically Speaking blog.

Acknowledgments

Big thanks to Rick Wicklin, who helped me quite a bit with this example. Rick validated my initial approach, and also provided valuable suggestions to improve the heat map and the statistical meaning of the example. He pointed me to http://colorbrewer.org, which provides examples of useful color ranges that you can apply in maps -- colors that are easy to read and don't distract from the meaning.

Rick told me that he is working on some related work coming up on his blog and within SAS 9.4, so you should watch his blog for additional insights.

tags: business analytics, GTL, ODS Graphics, SAS programming, Visual Analytics