BookmarkSubscribeRSS Feed
hollandnumerics
Pyrite | Level 9

I'm approaching my retirement, so learning about SAS Visual Analytics is not high on my To Do list. However, I recently discovered a sparsely documented graphics feature in the Data Step that I thought had been removed decades ago.

 

DSGI (Data Step Graphics Interface) used to be THE way to create free-form plots, so, when I discovered it was still there in SAS 9.4M8, I had to include this program in my new book:

 

/* set the graphics environment */
GOPTIONS RESET = GLOBAL GUNIT = PCT BORDER
         HSIZE = 18 CM VSIZE = 12 CM
         DEVICE = PNG;
/* execute a DATA step with DSGI */
DATA heart;
   /* initialize SAS/GRAPH software to accept DSGI statements */
   rc = GINIT();
   rc = GRAPH("CLEAR");
   /* assign colours to colour index */
   rc = GSET("COLREP", 1, "BLUE");
   rc = GSET("COLREP", 2, "RED");
   /* define and display titles */
   rc = GSET("TEXCOLOR", 1);
   rc = GSET("TEXFONT", "SWISSB");
   rc = GSET("TEXHEIGHT", 6);
   rc = GDRAW("TEXT", 90, 83, "Heart");
   /* change the height and display second title  */
   rc = GSET("TEXHEIGHT", 4);
   rc = GDRAW("TEXT", 90, 75, "Created with DSGI");
   /* change the height and display footnote  */
   rc = GSET("TEXHEIGHT", 4);
   rc = GDRAW("TEXT", 130, 15, "SAS");
   /* define and draw heart */
   rc = GSET("LINCOLOR", 2);
   rc = GSET("LINWIDTH", 1);
   pi = CONSTANT('PI');
   centerx = 110;
   centery = 40;
   scalex = 30 / 16;
   scaley = 30 / 18;
   DO t = 0 TO (2 * pi) BY 0.01;
      x = centerx + scalex * (16 * SIN(t) ** 3);
      y = centery + scaley * (13 * COS(t) - 5 * COS(2 * t)
                              - 2 * COS(3 * t) - COS(4 * t));
      IF t > 0 THEN rc = GDRAW("LINE", 2, x0, x, y0, y);
      OUTPUT;
      x0 = x;
      y0 = y;
   END;
   /* display graph and end DSGI */
   rc = GRAPH("UPDATE");
   rc = GTERM();
RUN;

dsgi heart.png

Philip R Holland
Holland Numerics: Blog and Forums
http://blog.hollandnumerics.org.uk

Explore and visualize your data

 
With a free 14-day SAS® Viya trial, you can:

 

  • Experience all the capabilities of SAS Viya Enterprise, our top-tier Viya offering.
  • Use our pre-loaded data or upload your own (up to 1GB).
  • Access training resources and videos.
  • Add up to four other users so your team can see how Viya works for everyone.
Register Now
Discussion stats
  • 0 replies
  • 300 views
  • 2 likes
  • 1 in conversation