Lapis Lazuli | Level 10

## Fun With SAS ODS Graphics: Betsy Ross Edition

With the July 4th weekend upon us, thought I'd make-like-Betsy-Ross and knock out a short program to "stitch" an American flag using specs found on Wikipedia. Happy Fourth of July, everyone!

``````* Fun w/SAS ODS Graphics, July 4th Stars-and-Stripes Edition (U.S. Flag)
Based on specs from wikipedia.org/wiki/Flag_of_the_United_States;

data stars(keep=x y);                                 /* Generate x/y points for 50 stars */
do r=1 to 9;                                          /* 9 rows of stars */
y=1-r*0.0538;
do x=0.0633*(1+mod(r-1,2)) to 11*0.0633 by 2*0.0633;/* Odd rows have 6 stars, even have 5 (offset by 1) */
output;
end;
end;

data stripes(keep=spolygon sx sy);                    /* Generate x/y points for 7 red stripes */
do stripe=1 to 13 by 2;                               /* Need seven rectangles (polygons) */
spolygon+1;                                         /* Rectangle counter */
sx=0;    sy=stripe*0.0769;     output;              /* Upper left x/y point */
sx=1.92; sy=stripe*0.0769;     output;              /* Upper right x/y point */
sx=1.92; sy=(stripe-1)*0.0769; output;              /* Lower right x/y point */
sx=0;    sy=(stripe-1)*0.0769; output;              /* Lower left x/y point */
end;

data canton(keep=cpolygon cx cy);                     /* Generate x/y points for 1 canton (blue rectangle) */
cpolygon+1;                                           /* Rectangle counter */
cx=0;    cy=1;        output;                         /* Upper left x/y point */
cx=0.76; cy=1;        output;                         /* Upper right x/y point */
cx=0.76; cy=1-0.5385; output;                         /* Lower right x/y point */
cx=0;    cy=1-0.5385; output;                         /* Lower left x/y point */

data flag;                                            /* Combine 3 datasets used to plot U.S. flag into 1 */
set stars stripes canton;

ods graphics on / reset=index border=off imagefmt=gif /* Plot American flag */
antialias height=5in width=9.5in;
proc sgplot data=flag noautolegend noborder pad=0;
symbolchar name=uniStar char='2605'x;                 /* Unicode value for 5-pointed star */
xaxis display=none offsetmin=0 offsetmax=0 values=(0 1.9);
yaxis display=none offsetmin=0 offsetmax=0 values=(.005 1);
polygon x=sx y=sy id=spolygon / fill fillattrs=(color=CXB22234) nooutline;  * Stripes ("Old Glory Red");
polygon x=cx y=cy id=cpolygon / fill fillattrs=(color=CX3C3B6E) nooutline;  * Canton ("Old Glory Blue");
scatter x=x y=y / markerattrs=(symbol=unistar color=CXFFFFFF size=38pt);    * Stars (White);``````

1 ACCEPTED SOLUTION

Accepted Solutions
Lapis Lazuli | Level 10

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Vertical bar chart-based Flag of Ireland

``````* Fun w/SAS ODS Graphics, Flag of Ireland (en.wikipedia.org/wiki/Flag_of_Ireland);

data flag;                                       /* Generate x/y points for stripes */
y=1.5; do x=1 to 3; output; end;

ods listing gpath='/folders/myfolders';          /* Generate bar chart flag */
ods graphics on / reset antialias noborder width=6in height=3in imagename="irishflag";
proc sgplot data=flag noautolegend pad=0 aspect=.5 noborder nowall;
vbar x / response=y  colorresponse=x colormodel=(CX169B62 CXFFFFFF CXFF883E)
barwidth=1 nooutline baselineattrs=(thickness=0);
xaxis display=none min=.5 max=3.5 offsetmin=.16667 offsetmax=.16667;
yaxis display=none min=0 max=1.5 offsetmin=0 offsetmax=0;``````
19 REPLIES 19
Super User

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

@tc

Awesome !.

The flag of China is much more simpler to plot than America.

Someone could polot your own country 's flag ?

``````data have;
x=5;y=15;star=unicode('\u2605');output;star=' ';
x=10;y=11;star1=unicode('\u2605');output;star1=' ';
x=10;y=18;star2=unicode('\u2605');output;star2=' ';
x=12;y=13;star3=unicode('\u2605');output;star3=' ';
x=12;y=16;star4=unicode('\u2605');output;
run;

proc sgplot data=have aspect=0.6 noautolegend noborder;
styleattrs wallcolor=red;
text x=x y=y text=star/ textattrs=(color=yellow size=80pt) ;
text x=x y=y text=star1/ textattrs=(color=yellow size=40pt) rotate=60;
text x=x y=y text=star2/ textattrs=(color=yellow size=40pt ) rotate=60;
text x=x y=y text=star3/ textattrs=(color=yellow size=40pt ) ;
text x=x y=y text=star4/ textattrs=(color=yellow size=40pt) rotate=20;

xaxis display=none offsetmin=0 offsetmax=0 values=(0 30);
yaxis display=none offsetmin=0 offsetmax=0 values=(0 20);
run;``````

Community Manager

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Love these @tc and @Ksharp! We'll end up with the United Nations via SGPLOT before you know it!

Meteorite | Level 14

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Nicely done.  I like the use of the rotated star character in the flags.

Lapis Lazuli | Level 10

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Vertical bar chart-based Flag of Ireland

``````* Fun w/SAS ODS Graphics, Flag of Ireland (en.wikipedia.org/wiki/Flag_of_Ireland);

data flag;                                       /* Generate x/y points for stripes */
y=1.5; do x=1 to 3; output; end;

ods listing gpath='/folders/myfolders';          /* Generate bar chart flag */
ods graphics on / reset antialias noborder width=6in height=3in imagename="irishflag";
proc sgplot data=flag noautolegend pad=0 aspect=.5 noborder nowall;
vbar x / response=y  colorresponse=x colormodel=(CX169B62 CXFFFFFF CXFF883E)
barwidth=1 nooutline baselineattrs=(thickness=0);
xaxis display=none min=.5 max=3.5 offsetmin=.16667 offsetmax=.16667;
yaxis display=none min=0 max=1.5 offsetmin=0 offsetmax=0;``````
Obsidian | Level 7

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Although U.S. flag works, China flag does not work on my machine.

My SAS Current version: 9.04.01M3P062415.

Super User

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

I am using SAS University Edition .
Super User

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

I also tried Chinese version SAS . and got this .

Super User

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

if you are using English version SAS, you could change its encoding as utf-8 .

D:\SASHome\SASFoundation\9.4\sas.exe -CONFIG "D:\SASHome\SASFoundation\9.4\nls\u8\sasv9.cfg"

And I also got star .

Community Manager

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Check out this article from @RobPratt - optimizing the placement of stars on the flag.  In it, he tackles the mathematical solution for arranging 51 stars if we were to add Puerto Rico to our official state roll call.

Lapis Lazuli | Level 10

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

And, inspired by a Sunday morning visit to the Bolingbrook IKEA, heeere's the Flag of Sweden!

``````* Fun w/SAS ODS Graphics: Band plot Flag of Sweden (specs at wikipedia.org/wiki/Flag_of_Sweden);

data flag;                                                  /* Generate dummy x/y point */
retain x y -1;

ods listing gpath='/folders/myfolders';                     /* Use band plots to generate flag image */
ods graphics on / reset antialias noborder width=8in height=5in imagename="swedenflag";
proc sgplot data=flag noautolegend pad=0 aspect=.625;       /* Proportion 5:8 = .625 */
styleattrs wallcolor=CX2D5FA1;                              /* 4055-R95B -> #2d5fa1 (Background) */
yaxis display=none min=0 max=10 offsetmin=0 offsetmax=0;    /* Colors: w3schools.com/colors/colors_ncs.asp */
xaxis display=none min=0 max=16 offsetmin=0 offsetmax=0;
band x=x lower=4 upper=6 / fillattrs=(color=CXFFCA20);      /* 0580-Y10R -> #ffca20 (4:2:4 Vertical) */
band y=y lower=5 upper=7 / fillattrs=(color=CXFFCA20);      /* 0580-Y10R -> #ffca20 (5:2:9 Horizontal) */``````
Calcite | Level 5

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

This is my first post and this is the first time I have used SAS ODS Graphics. I tried my level best to make it look perfect. If there is any flaws, kindly please forgive me. Thanks!

``````/* Flag of India - https://en.wikipedia.org/wiki/Flag_of_India */

data bands;                                                  				/* m/n point for the Saffron and Green Band */
retain m n -1;

data chakra(keep=i j);														/* i/j point for the Chakra(Circle) */
i=8; j=4.65; output;

data spokes;																/* x/y point for the Spokes */
x=8; y=4.51;line='|';output;line=' ';
run;

data flag;																	/* Combine the datasets bands, chakra & spokes */
set bands chakra spokes;

ods graphics on / reset antialias noborder width=6in height=4in imagename="indianflag";
proc sgplot data=flag noautolegend pad=0 aspect=.525;						/* Plot Indian Flag */
symbolchar name=circle char='25cb'x;										/* Unicode value for Circle */
yaxis display=none min=0 max=9 offsetmin=0 offsetmax=0;
xaxis display=none min=0 max=16 offsetmin=0 offsetmax=0;
band x=m lower=0 upper=3 / fillattrs=(color=CX138808); 						/* Saffron: (RGB: 255, 153, 51) (hex code: #FF9933) */
band x=m lower=6 upper=9 / fillattrs=(color=CXFF9933); 						/* Green: (RGB: 19, 136, 8) (hex code: #138808) */
scatter x=i y=j / markerattrs=(symbol=circle color=darkblue size=265pt);
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=15;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=30;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=45;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=60;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=75;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=90;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=105;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=120;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=135;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=150;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=165;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=180;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=195;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=210;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=225;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=240;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=255;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=270;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=285;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=300;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=315;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=330;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=345;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=360;``````

SAS Super FREQ

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Hi @Siddharthan,

Good job. I'm sure several people will point out that you could replace those multiple TEXT statements with a macro call:

``````%macro makeSpokes;
%do r = 15 %to 360 %by 15;
text x=x y=y text=line / textattrs=(color=darkblue size=65pt) rotate=&r;
%end;
%mend;

proc sgplot data=flag noautolegend pad=0 aspect=.525;						/* Plot Indian Flag */
symbolchar name=circle char='25cb'x;										/* Unicode value for Circle */
yaxis display=none min=0 max=9 offsetmin=0 offsetmax=0;
xaxis display=none min=0 max=16 offsetmin=0 offsetmax=0;
band x=m lower=0 upper=3 / fillattrs=(color=CX138808); 						/* Saffron: (RGB: 255, 153, 51) (hex code: #FF9933) */
band x=m lower=6 upper=9 / fillattrs=(color=CXFF9933); 						/* Green: (RGB: 19, 136, 8) (hex code: #138808) */
scatter x=i y=j / markerattrs=(symbol=circle color=darkblue size=265pt);
%makeSpokes;
run;``````

Calcite | Level 5

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

Noted with that Thanks! @Rick_SAS

Fluorite | Level 6

## Re: Fun With SAS ODS Graphics: Betsy Ross Edition

An annotate solution for France :

``````data WORK.ANNO;
length function \$ 8 color style \$ 32;

xsys='1'; ysys='1'; hsys='3'; when='a';

/* Fun with flags? */

function = 'move';  x =  0;  y =   0; output;
function = 'bar' ;  x =  33; y = 100; color = 'cx051440' ; style='SOLID'; output;
function = 'move';  x =  33; y =   0; output;
function = 'bar' ;  x =  66; y = 100; color = 'white'    ; style='SOLID'; output;
function = 'move';  x =  66; y =   0; output;
function = 'bar' ;  x = 100; y = 100; color = 'cxEC1920' ; style='SOLID'; output;

run;

goptions xpixels=900 ypixels=600;
proc gslide des="France" name="France" anno=WORK.ANNO;
run;quit;``````

Discussion stats
• 19 replies
• 6724 views
• 82 likes
• 10 in conversation