%let name=spiral;
filename odsout '.';

/*
Each 360-degree circle around the spiral is 1 year of data.
Each line segment represents a day (~365 days a year).
You could have fewer than 365 days, but the days still need to
be numbered with their day-of-year numbering sequence (1-365).

This example just uses random data - you'd want to swap in your
own real data, and modify the if/else to suit your own coloring
desires.
*/


/* "sales" is the length of the line segment, 'normalized' to a value 0-1 */
data my_data;
length color $20;
do year=2007 to 2010 by 1;
 do day=1 to 365 by 1;
  sales=ranuni(9823)*1;
  if ranuni(9835)<.3 then color='red'; else color='blue';
  /* shorten the normalized value just a little, so spirals don't touch */
  sales=sales*.9;
  output;
  end;
 end;
run;


data spiral; set my_data;
by year;
 length function color $ 12 text $ 30;
 xsys='2'; ysys='2'; hsys='3'; when='a';

if first.year then year_offset+1;

degrees=year_offset*360 + (day/365)*360;

radius=year_offset+(day/365);
   
x=(radius * cos(degrees/57.3));
y=(radius * sin(degrees/57.3));
function='move'; output;

x=((radius+sales) * cos(degrees/57.3));
y=((radius+sales) * sin(degrees/57.3));
function='draw'; 
size=.01; 
output;

run;


goptions device=png;
goptions xpixels=600 ypixels=650;
 
ODS LISTING CLOSE;
ODS HTML path=odsout body="&name..htm"
 (title="Spiral Chart") 
 style=htmlblue;

goptions border;

goptions gunit=pct htitle=4.25 htext=2.75 ftitle="albany amt/bold" ftext="albany amt";

/* 
Hard-code same length for x & y axes, to guarantee it is "square"
(otherwise spiral might be 'squished/stretched').
And, don't want to see the numbers or tickmarks on the axes 
*/
axis1 length=5in label=none major=none minor=none value=none style=0;
axis2 length=5in label=none major=none minor=none value=none style=0;

/* 
make the plot symbol 'invisible' (the annotated move/draw line segments 
is all we want to see 
*/
symbol1 v=none i=none;

title1 ls=1.5 "Custom SAS/Graph spiral chart";

proc gplot data=spiral anno=spiral;
plot y*x=1 /
 href=0 vref=0 chref=grayaa cvref=grayaa
 vaxis=axis1 haxis=axis2
 des='' name="&name"; 
run;

quit;
ODS HTML CLOSE;
ODS LISTING;
