by: Robert Allison
V9.2 SAS/Graph (shipping in Spring 2008) has a *lot* of additions & enhancements you'll want to know about! Some of the changes will make your output look better and make SAS/Graph easier to use, while others add totally new functionality. Here are several examples that just might improve your "quality of life" as a sas user!
V9.2 SAS/Graph supports over 16 million colors! This is probably the biggest & most exciting change, in my opinion, and will have a profound impact on the quality of your graphics output.
Prior to v9.2, SAS/Graph had a limit of 256 colors. The 256 colors are not only consumed by the colors you specify, but also the shades of colors that are needed for anti-aliasing the edges of fonts, gradient shading on the sides of 3d cylinder-shaped gchart bars, images you include in the graph, etc. When you run out of colors, the results are a bit "unpredictable".
This increase in colors is only supported in certain SAS/Graph devices such as device=png (device=gif, for example, will never support >256 colors in SAS/Graph, because the gif standard itself does not support >256 colors). Therefore, if you have sas jobs that are hard-coded to use device=gif, you'll want to change them to use device=png. Device=png is the new default in v9.2, therefore if you haven't hardcoded a device, then you'll automatically get device=png.
With more colors, your output can look better because more shades are available, therefore when images/photos are incorporated into graphs they have a more true/undithered look, as demonstrated in the example below. (click here to see sas code)
Also, when SAS/Graph only supported 256 colors, it was unable to display all of the 292 "named" SAS/Graph colors (as demonstrated in the first/left graph below), and after it runs out of colors, it uses dark yellow for the additional color-swatches and the outlines around the annotated color rectangles (in this particular example), and the anti-aliasing around the edges of the title text looks very bad. In v9.2 all 292 named SAS/Graph colors can be displayed in a single graph, and the anti-aliasing around the title text looks much better: (sas code)
In V9.2 SAS/Graph, the default fonts are nice smooth-edged (anti-aliased) fonts, and will look much better than in previous versions. You can also use these new fonts (such as "Albany AMT", which looks like "Arial") on all hosts (Windows, Unix, Mainframe), thereby making it easier to write code which will produce nice output no matter where you run it.
Prior to v9.2, SAS/Graphs used the SAS/Graph software fonts as the default. The SAS/Graph software fonts are not rendered with smooth (anti-aliased) edges, and can look somewhat 'jagged'. The reason the sas/graph software fonts were previously used as the default (as opposed to some of the nicer truetype and other fonts that might be on your system) is that they were the only fonts guaranteed to always be there, and look/work the same, on all hosts.
For v9.2, sas bought re-distribution rights for several nice-looking fonts from the font foundry called 'Monotype Imaging' (the term 'foundry' comes from the days of old when companies actually used lead to make the font characters). Now you can run the exact same sas code on Windows, Unix, and Mainframes, without having to change the font. Albany AMT is used as the default graph font in most cases in v9.2. The example below shows a 'proc gslide' with a title1 & title2, to show the default ftitle & ftext. (sas code)
Also new in v9.2, Unicode character codes can be used to specify characters in a font. (Note that the Unicode support only applies to fonts, such as TrueType fonts, which support Unicode.) To see these characters, you can run the Start->Programs->Accessories->System_Tools->Accessories->Character_Map on Windows, and select a font such as Arial, and scroll way down in the list, and click on some of the more interesting characters, and see the 4 hex-digit codes for them (see the screen-capture on the left, below). The example below shows using the arial/unicode 'euro symbol' ('20ac'x) in the axis label and footnote, and the 'smiley face' character ('263b'x) as the plot symbol (sas code). The code snip-it's below show how the unicode values were specified in the sas code:
axis1 label=(font="arial/bold" 'Sales ' font="arial/bold/unicode" '20ac'x )
footnote "Sales plot - all values in " font="arial/unicode" '20ac'x;
symbol1 font="arial/unicode" value='263b'x
Note that in the 9.2 TS1M0 release, unicode character codes that contain a '20'x (such as the '20ac'x euro symbol) do not work as gplot symbols. This problem is fixed in 9.2 TS2M0. See the following SAS Note for more details.
The new v9.2 fonts also helped improve the output for some of non-SAS/Graph procs that use SAS/Graph technology to draw graphs. For example, in v9.1.3 Proc Shewhart required you to use the jagged-edged SAS/Graph software fonts, in order to get statistical characters such as 'sigma' to show up on the graph correctly - if you specified a nice smooth-edged font (such as 'Arial') then the sigma character (near the top/right of the graph below) looked bad. With the new fonts in v9.2, the special statistical characters (such as sigma) should always look good, no matter which font you specify. This enhancement should greatly help, in producing publication-quality output from these procs, for inclusion in magazines, etc. (sas code)
In v9.2, you can use the new Graph Styles to automatically assign pleasing color combinations for the background, the text, the axes, and the chart elements (such as bars, plot lines, map areas, etc). They also control the font of the text, and some come with a decorative background image. This gives you a very easy way to quickly generate fancy graphs with a lot of 'flash' and 'pizzazz', without writing a lot of code.
Below are some examples of v9.2 graphs using various styles using device=png
(previously the graph styles only worked with java & activex) - the name of the
style is in the title of the graph.
You can get a complete list of all the ODS graph styles by submitting the following sas code:
proc template; list styles; run;
(sas code)
ODS Graphics (sometimes known as 'stat graph') is going production for many procs in v9.2. In the past, the SAS/Stat procs did analytics and produced output data sets and tables (and sometimes basic ASCII-art plots), and the users had to then write their own SAS/Graph code to produce nice "publication-quality" plots of the results. In v9.2, you can now specify "ods graphics on" and fancy graphical representations will be automatically created for you, for many SAS/Stat procs (and procs from a few other products, such as SAS/ETS and SAS/QC, as well). Prior to v9.2, "ods graphics on" was experimental and you did not need a SAS/Graph license to use it - now that it is production you do need a SAS/Graph license.
Below is a comparison of Proc Reg's old ASCII output to the new "ods graphics on" output.
This first plot is an example screen-capture of an old V9.1.3 (non-"ods graphics") output plot -- it is created from ASCII characters (letters, numbers, _, |, etc) - markers in the plot are represented by a '1' and if multiple markers are too close to represent as two '1's, then they are represented by a '2'. ASCII-art plots are not generally considered "publication-quality". The two examples below it show a few of the nice publication-quality plots created by the v9.2 "ods graphics on".
And here are a couple of the new V9.2 "ods graphics on" plots - the top/left plot is the same data as was represented in the ASCII-art plot above. In addition to higher-quality plots, "ods graphics on" produces more plots, and more complex plots (such as histograms with smooth overlaid lines). (sas code)
In v9.2, you can now specify a width variable in your annotate data set, to control the width of circles drawn with the 'pie' function. The following example demonstrates the new width functionality, and also shows off the new/improved v9.2 maps.world which contains Cuba, Newfoundland, Tasmania, and Antarctica (which were missing in the v9.1.3 map). (sas code)
V9.2 SAS/Graph has a new arrow annotate function, which allows you to easily draw arrows, similar to how you draw line segments using the move/draw annotate functions. Previously, you had to work out all the geometry and draw the arrow heads using move/draw line segments (or annotate a wedge of a pie slice in just the right position and orientation so that it looks like an arrow head). This new 'arrow' function will make life *much* easier! (sas code)
Prior to v9.2, transparency did not work in many situations in SAS/Graph - either in creating a graph with a transparent background, or in using an image (be it a graph, or a picture) with a transparent background.
In v9.2, it's all working exactly as you would hope & expect, for GIFs with transparent backgrounds! The example below demonstrates annotating 2 pictures with transparent backgrounds onto a map. Notice in v9.2 (where annotate is honored) that the pictures blend smoothly with the map's gradient background, whereas in v9.1.3 the pictures block off a rectangular area of white space. (sas code)
One possible "gotcha" to be on the lookout for though ... if you're creating SAS/Graph's that you want to annotate onto other SAS/Graphs (or maps, or whatever), then be sure to use device=gif with the "goptions transparency" to create the graphs you're going to be annotating. If you use device=pngt to create the graphs with transparent background, that type of transparency is not honored by SAS/Graph annotte. As long as you stick with using GIFs with transparent background, you should not have a problem.
The NAME= option for SAS/Graph procedures has been enhanced to allow you to specify filenames up to 256 characters (previous limit was 8 characters) for graphics output files (PNG files, GIF files, and so on). Name= also allows the use of #byval in the name, which now allows you to use values from the data to easily produce long meaningful/mnemonic filenames when you're using "by" statements. This will make life *much* easier on you, if you care about output filenames, (for example, if you use the filenames as drilldowns in web pages). Right-click on the gslide examples below, and view the 'properties' to see their gif filenames. (sas code)
Several SAS/Graph Procs have been added in v9.2 that provide exciting new graphical functionality. They provide an easy way to generate graphics that were out of reach of most sas users in the past (because they would have required much custom programming & use of annotate to create in previous releases). Now you can simply run these new procs, and *poof*, you have the neat new graphic!
Proc GKPI (which stands for Graphical Key Performance Indicator) is a new proc that produces several widgets that people seem to want for their dashboards. I won't get into the discussion about whether or not dials & gauges are "good" to use, but this proc now makes them easy to use :) (sas code)
Proc GKPI can produce Bullet and Slider graphs:
And also Dial, Speedometer, and Traffic Light graphs:
Proc GTILE creates Tree Maps (or Tile Charts). In these graphs, one variable controls the size of the rectangle, and another variable controls the color. The following example shows the Year 2000 election results - the size of the rectangles represents the number of votes in each state, and the color represents the winner of the votes. (sas code)
Proc GINSIDE allows you to programmatically determine whether a given point is inside of a given map area. This is very handy for doing geo-spatial analytics about your customers, tracking the spread of diseases, performing environmental impact studies, etc. (sas code)
Proc GEOCODE allows you to estimate the latitude/longitude location
of an address. In this first release (9.2-classic) proc geocode will only estimate
the location down to the city or zipcode level. Using proc geocode to calculate
the average centroid of a city's zipcodes is much easier than manually calculating
the average location using SQL queries or other sas procs to calculate it.
Quite literally, it only takes this much code to do city-level geocoding:
proc geocode CITY data=teams out=teams;
In future releases, hopefully street-level geocoding will be added.
Once you have the geocoded lat/long coordinates, you can annotate markers
onto a map at those locations, such as the map below:
(sas code)
Proc Geocode can also do ZIP+4 geocoding. Note that regular zipcode-level geocoding is a bit easier, because it uses the sashelp.zipcode file that ships with sas -- to do zip+4 geocoding, you must download a large lookup data set with the zip+4's and their lat/long centroids. You can download a zip+4 data set derived from the Census Bureau 2006 Second Edition TIGER files, from the SAS maps online website.
The two examples below demonstrate the difference between the regular zipcode-level geocoding and zip+4 geocoding. The geocoded centroids of all of the regular (5-digit) zipcodes based in Wake county North Carolina are plotted on a Wake county map on the left, and the zip+4 locations of all those same zipcodes are plotted on the map to the right. Zip+4 gives you a *whole* lot more precision/granularity. (sas code) (sas code +4)
In the v9.2-platform release (which will ship sometime after the v9.2-classic release), proc geocode will add support for geocoding IP addresses. This can help you spatially analyze your web logs and find out where your web traffic is coming from, which can be *very* useful for your sales analytics, security monitoring, etc. Here's an example that shows what you might do with geocoded IP address locations. (sas code)
Several of the existing SAS/Graph procs have been enhanced in v9.2. New features & options were added, bugs were fixed, etc. These enhancements should help improve the quality of your graphs - and maybe your quality of life, as well! ;)
Proc GBARLINE has several nice enhancements in v9.2. Previous versions of GBARLINE allowed only a single PLOT statement referencing one variable and generating one plotted line. You can now use multiple PLOT statements with different variables to graph separate lines. The SUBGROUP option was added to the BAR statement, which allows bars with stacked subgroups. This behavior is identical the SUBGROUP option in PROC GCHART's VBAR statement. Support for the LEGEND option was also added. You can use it on either the BAR or a PLOT statement or on both. You cannot use it on more than one PLOT statement. It does not have to be on the first PLOT statement, but you are limited to one PLOT legend. You can position the BAR and PLOT legends independently, e.g. upper left for BAR and lower left for PLOT. You can also put them in the same position and they are drawn as one legend. Also, previously if you used the 'descending' option, the line didn't look right because it was connected in data-order rather than descending left-to-right order - that problem is fixed in v9.2. (sas code)
Proc MAPIMPORT allows you to import ESRI shape files into sas, so you can use them as SAS/Graph maps with Proc Gmap. In v9.1.3 Proc Mapimport didn't allow you to specify an 'id' variable, therefore if map areas had multiple segments they got interconnected by what appeared to be a 'stray' line in the map, and this also caused the polygons to sometimes be drawn incorrectly (you would generally see big triangles) - there were some work-arounds whereby you could add your own 'segment' variable (but that's a lot of work). Without the work-arounds an imported zipcode map would look like the v9.1.3 map below, for example.
In v9.2, Proc Mapimport has been enhanced, and allows you to specify an 'id' variable (such as 'id zcta' in a zipcode map) - and with knowledge of the id variable, it can better intuit when it is encountering disjoint 'segments' of a map area. Therefore the v9.2 imported maps look and work *much* better, without requiring you to use kludges to add your own segment variable, etc. This is a tremendous improvement, and should be a big help for those that need to import maps into sas.
The example below also shows off the new pattern colors & shades which are the default in v9.2 (as opposed to the short list of primary colors which gets reused when it runs out in the v9.1.3 example above). (sas code)
Even good-old Proc GMAP has several enhancements in v9.2.
One simple, but very useful enhancement is an option that allows you to easily control the default fill color (cdefault) of the 'empty' map areas (ie, those with no data). Previously, the 'cempty' option allowed you to control the outline color of the empty areas, but if you wanted to control the fill color you had to insert fake response values into your data for all those areas (otherwise the areas with no data were indeed 'empty', and you could see the background color through them). Now, in v9.2, you can simply specify cdefault={some color} option to control the color of the areas with no data. (sas code)
Prior to v9.2, if you wanted to reduce the complexity of the borders of a map, you had to run "proc greduce" to add a 'density' variable to the map, and then use a 'where' clause to subset the map based on the values of that density variable. In v9.2, many of the larger maps already have a 'density' variable in them, and there is a new density option in Proc Gmap which allows you to easily specify the level of density you desire in the map.
In the example below, notice that in the v9.1.3 map (which uses all the boundary data points) there is so much resolution trying to be represented along the Canadian west coast, that the data points all merge together and form a thick 'blob'. By comparison in the v9.2 map on the right, which only uses the boundary data points with a density value of 1 or lower, the boundaries look much more clear/un-cluttered. (sas code)
Another enhancement is the ability to easily create maps with gradient shading. Previously, you had to specify each of the gradient colors in the pattern statements (which can be a daunting task). Now, through the use of the "graph styles", you can produce maps with gradient shading by using the new SAS/Graph styles -- just modify the style to specify the start & end colors, and use gmap's levels= option to specify the number of shades to use in the gradient coloring. And since the Graph styles work for all devices now, this isn't just an activex/java thing - the gradient map below was created using device=gif, for example! (Note that the map below is shaded by county, and has annotated state outlines.)
Here's the code used to modify the graph style, and specify the start & end colors for the gradient used in the map below: (sas code)
proc template;
define style styles.mygradient;
parent=styles.listing;
style twocolorramp / startcolor=yellow endcolor=red;
end; run;
Proc GPLOT has one 9.2 (re-)enhancement worth mentioning...
In v8.2, when you had multiple lines in a plot, with different line widths, the legend honored/showed those widths. In v9.1.3 that functionality was removed. Thankfully, in v9.2 that functionality was added back! (sas code)
The HTML= option has been ehanced for *all* the SAS/Graph procs in SAS 9.2 ... In SAS 9.1.3 the html= option only allowed a string (for the html charttip and drilldown) of about 1000 characters, and it silently truncated the string if it was longer (and if it truncated quotes off the end of the string, then you had mal-formed html charttips and/or drilldowns that mysteriously didn't work). In SAS 9.2, this length limit has been lifted, and you can now have *very* long strings for the html charttip and drilldown. (sas code)
There have been several changes and updates to the SAS/Graph Map Data Sets (the ones you use with 'proc gmap') in SAS 9.2.
Finally - Updated Maps in SAS 9.2! Several of the map data sets have been updated, enhanced, or corrected. See the SAS Help for a complete list. The example below (same example used previously to show the new annotated circle 'width') shows that several land-masses that were missing in v9.1.3 have been added to the v9.2 maps.world (such as Cuba, Newfoundland, Tasmania, and Antarctica): (sas code)
Descriptive Map Data Set Labels have been added to all the SAS/Graph Map data sets in the 'Maps' library. You can see these labels as the text in the 'Description' field in the DMS sas 'explorer' and also when you run 'proc contents' on the map data sets. To see the data set labels in the SAS explorer, you'll need to do the following:
Run sas. Run 'explore' in the sas command line. Run the 'View->Details' pulldown menu. And then... Run 'Tools->Options->Explorer', go to the 'General' tab, and check 'Member Details' -or- Submit 'options details;' from the SAS program editor
Here is a screen capture of v9.2 sas, showing the type of 'Description' info you'll see in the sas explorer, for the Maps data sets: