hi,
i have a problem with a proc gchart, the code is down.
Can you help me please?
1) the resolution is low, how can I increase it?
2) how can I insert a line in the graph at 94%?
3) how can I change the format of the x axis from decimal to percentage?
Thank's so much
%let name=bar_table;
filename odsout '.';
data atm_expo.pga2007;
input Rank Area_commerciale $ 4-18 N_TERM N_TERM_Sotto_soglia Rounds CutsMade Top10 Wins media_lds_prel;
format Earnings PERCENT8.1;
datalines;
1 Tiger Woods 33 16 61 16 12 7 0.10
2 Phil Mickelson 38 22 73 16 7 3 0.10
3 Vijay Singh 45 27 101 25 7 2 0.10
4 Steve Stricker 41 23 80 19 9 1 0.10
5 K.J. Choi 38 25 88 20 7 2 0.10
6 Rory Sabbatini 32 23 80 18 10 1 0.10
7 Jim Furyk 38 24 84 20 8 1 0.10
8 Zach Johnson 32 23 78 18 5 2 0.10
9 Sergio Garcia 29 19 67 16 7 0 0.10
10 Aaron Baddeley 27 23 82 19 7 1 0.20
;
run;
data atm_expo.pga2007; set atm_expo.pga2007;
length my_html $300;
my_html='title='||quote(trim(left(Area_commerciale))||': '||trim(left(put(media_lds_prel,PERCENT8.1))));
run;
data atm_expo.my_anno ; set atm_expo.pga2007;
length text $50 style $30;
function='label'; style=''; hsys='3'; when='a';
ysys='2'; midpoint=Area_commerciale;
/* annotate totals at end of bars */
xsys='2'; position='<';
text=trim(left(put(media_lds_prel,PERCENT8.1)))||'a0'x;
output;
/* annotate the values for the table to the left of the bar chart */
xsys='3'; position='5';
x=5; text=trim(left(N_TERM)); output;
x=12; text=trim(left(N_TERM_Sotto_soglia)); output;
/*x=19; text=trim(left(Wins)); output; */
run;
/* annotate the headings for the table to the left of the bar chart */
data atm_expo.headings;
length text $50 style $30;
function='label'; style='albany amt/bold'; hsys='3'; when='a';
xsys='3'; position='2';
ysys='1'; y=100;
x=5; text="N ATM"; output;
x=12; text="N <94%"; output;
/*x=19; text="Wins"; output;
x=63; text='Earnings'; output; */
run;
data atm_expo.my_anno; set atm_expo.my_anno atm_expo.headings;
run;
ods graphics on / reset=all border=OFF antialiasmax=10000 /* IMAGE_DPI=300 */ ; /*height=13CM width=23CM*/
ods listing gpath="C:\Users\ui43925\Desktop\p4cards LDS" /* IMAGE_DPI=300*/;
ODS LISTING STYLE=Default3;
filename outgraph "C:\Users\ui43925\Desktop\p4cards LDS\A1_2016.PNG";
axis1 label=none value=(justify=right font="albany amt/bold");
axis2 label=none order=(0.8 to 1 by 0.05)
style=0 major=none minor=none offset=(0,0);
title1 ls=1.5 "Andamento aree commerciali";
title2 h=5 ' ';
title3 angle=90 height=35pct " ";
title4 angle=-90 height=2pct " ";
pattern1 v=s c=cx1E90FF;
proc gchart data=atm_expo.pga2007 anno=atm_expo.my_anno;
hbar Area_commerciale / type=SUM sumvar=media_lds_prel descending nostats
maxis=axis1 raxis=axis2 noframe coutline=gray99
autoref cref=graydd clipref
html=my_html
des='' name="&name";
run;
quit;
dm 'odsresults; clear';
ods listing close;
You could add a variable with a different value for above/below the target value, and then use the subgroup= gchart option to color based on that variable, and use pattern statements to control the colors. Below is the code (note that I've modified one of your values to make it >=94%, to demonstrate that the bar will be blue)...
%let name=bar_table; filename odsout '.'; data pga2007; input Rank Area_commerciale $ 4-18 N_TERM N_TERM_Sotto_soglia Rounds CutsMade Top10 Wins media_lds_prel; if media_lds_prel<.94 then colorvar=1; else colorvar=2; format Earnings PERCENT8.1; datalines; 1 Tiger Woods 33 16 61 16 12 7 0.10 2 Phil Mickelson 38 22 73 16 7 3 0.10 3 Vijay Singh 45 27 101 25 7 2 0.10 4 Steve Stricker 41 23 80 19 9 1 0.10 5 K.J. Choi 38 25 88 20 7 2 0.10 6 Rory Sabbatini 32 23 80 18 10 1 0.10 7 Jim Furyk 38 24 84 20 8 1 0.10 8 Zach Johnson 32 23 78 18 5 2 0.10 9 Sergio Garcia 29 19 67 16 7 0 0.97 10 Aaron Baddeley 27 23 82 19 7 1 0.20 ; run; data pga2007; set pga2007; length my_html $300; my_html='title='||quote(trim(left(Area_commerciale))||': '||trim(left(put(media_lds_prel,PERCENT8.1)))); run; data my_anno ; set pga2007; length text $50 style $30; function='label'; style=''; hsys='3'; when='a'; ysys='2'; midpoint=Area_commerciale; /* annotate totals at end of bars */ xsys='2'; position='<'; text=trim(left(put(media_lds_prel,PERCENT8.1)))||'a0'x; output; /* annotate the values for the table to the left of the bar chart */ xsys='3'; position='5'; x=5; text=trim(left(N_TERM)); output; x=12; text=trim(left(N_TERM_Sotto_soglia)); output; /*x=19; text=trim(left(Wins)); output; */ run; /* annotate the headings for the table to the left of the bar chart */ data headings; length text $50 style $30; function='label'; style='albany amt/bold'; hsys='3'; when='a'; xsys='3'; position='2'; ysys='1'; y=100; x=5; text="N ATM"; output; x=12; text="N <94%"; output; /*x=19; text="Wins"; output; x=63; text='Earnings'; output; */ run; data my_anno; set my_anno headings; run; data anno_line; length function $8 color $8; xsys='2'; x=.94; ysys='1'; y=0; function='move'; output; ysys='1'; y=100; function='draw'; color='red'; size=.001; output; run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=6 htext=2.2; goptions ctext=gray33; axis1 label=none value=(justify=right font="albany amt/bold"); axis2 label=none /*order=(0.8 to 1 by 0.05)*/ order=(0 to 1.0 by 0.25) style=0 major=none minor=none offset=(0,0); title1 ls=1.5 "Andamento aree commerciali"; title2 h=5 ' '; title3 angle=90 height=35pct " "; title4 angle=-90 height=2pct " "; pattern1 v=s c=red; pattern2 v=s c=cx1E90FF; proc gchart data=pga2007 anno=my_anno; format media_lds_prel percentn7.0; hbar Area_commerciale / type=SUM sumvar=media_lds_prel descending nostats maxis=axis1 raxis=axis2 noframe coutline=gray99 subgroup=colorvar nolegend autoref cref=graydd clipref anno=anno_line html=my_html des='' name="&name"; run; proc print data=pga2007; run; quit; ODS HTML CLOSE; ODS LISTING;
Move to sgplot and graph template language, its far more powerful, and flexible. Here is an excellent blog which gives examples with code of virtually anything you can think of:
https://blogs.sas.com/content/graphicallyspeaking/
You can annotate an extra line at 94% using code like this:
data anno_line;
length function $8 color $8;
xsys='2'; x=.94;
ysys='1'; y=0; function='move'; output;
ysys='1'; y=100; function='draw'; color='red'; size=.001; output;
run;
You can change the format of the x-axis by adding a format line to proc gchart:
format media_lds_prel percentn7.0;
Here's my modified version of your code (note that I leave out the 'ods graphics' statement/options, since proc gchart doesn't use those), followed by the png output:
%let name=bar_table; filename odsout '.'; data pga2007; input Rank Area_commerciale $ 4-18 N_TERM N_TERM_Sotto_soglia Rounds CutsMade Top10 Wins media_lds_prel; format Earnings PERCENT8.1; datalines; 1 Tiger Woods 33 16 61 16 12 7 0.10 2 Phil Mickelson 38 22 73 16 7 3 0.10 3 Vijay Singh 45 27 101 25 7 2 0.10 4 Steve Stricker 41 23 80 19 9 1 0.10 5 K.J. Choi 38 25 88 20 7 2 0.10 6 Rory Sabbatini 32 23 80 18 10 1 0.10 7 Jim Furyk 38 24 84 20 8 1 0.10 8 Zach Johnson 32 23 78 18 5 2 0.10 9 Sergio Garcia 29 19 67 16 7 0 0.10 10 Aaron Baddeley 27 23 82 19 7 1 0.20 ; run; data pga2007; set pga2007; length my_html $300; my_html='title='||quote(trim(left(Area_commerciale))||': '||trim(left(put(media_lds_prel,PERCENT8.1)))); run; data my_anno ; set pga2007; length text $50 style $30; function='label'; style=''; hsys='3'; when='a'; ysys='2'; midpoint=Area_commerciale; /* annotate totals at end of bars */ xsys='2'; position='<'; text=trim(left(put(media_lds_prel,PERCENT8.1)))||'a0'x; output; /* annotate the values for the table to the left of the bar chart */ xsys='3'; position='5'; x=5; text=trim(left(N_TERM)); output; x=12; text=trim(left(N_TERM_Sotto_soglia)); output; /*x=19; text=trim(left(Wins)); output; */ run; /* annotate the headings for the table to the left of the bar chart */ data headings; length text $50 style $30; function='label'; style='albany amt/bold'; hsys='3'; when='a'; xsys='3'; position='2'; ysys='1'; y=100; x=5; text="N ATM"; output; x=12; text="N <94%"; output; /*x=19; text="Wins"; output; x=63; text='Earnings'; output; */ run; data my_anno; set my_anno headings; run; data anno_line; length function $8 color $8; xsys='2'; x=.94; ysys='1'; y=0; function='move'; output; ysys='1'; y=100; function='draw'; color='red'; size=.001; output; run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=6 htext=2.2; goptions ctext=gray33; axis1 label=none value=(justify=right font="albany amt/bold"); axis2 label=none /*order=(0.8 to 1 by 0.05)*/ order=(0 to 1.0 by 0.25) style=0 major=none minor=none offset=(0,0); title1 ls=1.5 "Andamento aree commerciali"; title2 h=5 ' '; title3 angle=90 height=35pct " "; title4 angle=-90 height=2pct " "; pattern1 v=s c=cx1E90FF; proc gchart data=pga2007 anno=my_anno; format media_lds_prel percentn7.0; hbar Area_commerciale / type=SUM sumvar=media_lds_prel descending nostats maxis=axis1 raxis=axis2 noframe coutline=gray99 autoref cref=graydd clipref anno=anno_line html=my_html des='' name="&name"; run; proc print data=pga2007; run; quit; ODS HTML CLOSE; ODS LISTING;
RobertAllison_S
Another problem:
If I run your query the image i get it is a lower resolution (see my attachment) of what you have attached ... 😞 .... why this difference the code is the same ? What should I change? do i can reset ODS at default (i have sas 9.2?
Another question:
IS it possibile make red the bar < 94% and blue >= 94% ?
Thank's!
I resolved, the problem was "albany amt/bold" i chenged in "arial". Now the immage is the same!!! thank's!!!
IS it possibile make red the bar < 94% and blue >= 94% ?
Hmm ... odd. The "albany amt" font should work with any recent version of SAS. The font is shipped with SAS, and it should be registered (proc fontreg) automatically during the SAS install. Perhaps something 'unexpected' was done during your SAS install (such as installing it in one location, and then moving it to another ... which would change the path to the fonts?) Oh well, at least you have found a work-around. The benefit of using "albany amt" is that it should work on any platform (windows, unix, mainframe) ... so hopefully you can get that working.
You could add a variable with a different value for above/below the target value, and then use the subgroup= gchart option to color based on that variable, and use pattern statements to control the colors. Below is the code (note that I've modified one of your values to make it >=94%, to demonstrate that the bar will be blue)...
%let name=bar_table; filename odsout '.'; data pga2007; input Rank Area_commerciale $ 4-18 N_TERM N_TERM_Sotto_soglia Rounds CutsMade Top10 Wins media_lds_prel; if media_lds_prel<.94 then colorvar=1; else colorvar=2; format Earnings PERCENT8.1; datalines; 1 Tiger Woods 33 16 61 16 12 7 0.10 2 Phil Mickelson 38 22 73 16 7 3 0.10 3 Vijay Singh 45 27 101 25 7 2 0.10 4 Steve Stricker 41 23 80 19 9 1 0.10 5 K.J. Choi 38 25 88 20 7 2 0.10 6 Rory Sabbatini 32 23 80 18 10 1 0.10 7 Jim Furyk 38 24 84 20 8 1 0.10 8 Zach Johnson 32 23 78 18 5 2 0.10 9 Sergio Garcia 29 19 67 16 7 0 0.97 10 Aaron Baddeley 27 23 82 19 7 1 0.20 ; run; data pga2007; set pga2007; length my_html $300; my_html='title='||quote(trim(left(Area_commerciale))||': '||trim(left(put(media_lds_prel,PERCENT8.1)))); run; data my_anno ; set pga2007; length text $50 style $30; function='label'; style=''; hsys='3'; when='a'; ysys='2'; midpoint=Area_commerciale; /* annotate totals at end of bars */ xsys='2'; position='<'; text=trim(left(put(media_lds_prel,PERCENT8.1)))||'a0'x; output; /* annotate the values for the table to the left of the bar chart */ xsys='3'; position='5'; x=5; text=trim(left(N_TERM)); output; x=12; text=trim(left(N_TERM_Sotto_soglia)); output; /*x=19; text=trim(left(Wins)); output; */ run; /* annotate the headings for the table to the left of the bar chart */ data headings; length text $50 style $30; function='label'; style='albany amt/bold'; hsys='3'; when='a'; xsys='3'; position='2'; ysys='1'; y=100; x=5; text="N ATM"; output; x=12; text="N <94%"; output; /*x=19; text="Wins"; output; x=63; text='Earnings'; output; */ run; data my_anno; set my_anno headings; run; data anno_line; length function $8 color $8; xsys='2'; x=.94; ysys='1'; y=0; function='move'; output; ysys='1'; y=100; function='draw'; color='red'; size=.001; output; run; goptions device=png; goptions noborder; ODS LISTING CLOSE; ODS HTML path=odsout body="&name..htm" style=htmlblue; goptions gunit=pct ftitle="albany amt/bold" ftext="albany amt" htitle=6 htext=2.2; goptions ctext=gray33; axis1 label=none value=(justify=right font="albany amt/bold"); axis2 label=none /*order=(0.8 to 1 by 0.05)*/ order=(0 to 1.0 by 0.25) style=0 major=none minor=none offset=(0,0); title1 ls=1.5 "Andamento aree commerciali"; title2 h=5 ' '; title3 angle=90 height=35pct " "; title4 angle=-90 height=2pct " "; pattern1 v=s c=red; pattern2 v=s c=cx1E90FF; proc gchart data=pga2007 anno=my_anno; format media_lds_prel percentn7.0; hbar Area_commerciale / type=SUM sumvar=media_lds_prel descending nostats maxis=axis1 raxis=axis2 noframe coutline=gray99 subgroup=colorvar nolegend autoref cref=graydd clipref anno=anno_line html=my_html des='' name="&name"; run; proc print data=pga2007; run; quit; ODS HTML CLOSE; ODS LISTING;
RobertAllison_S
Work great but in one case i have problem: when all the value is > 94% the bar is all red instead all blue, suggestion ?
This is the immage that i can insert in a ppt, the dimension (large) isn't than not be bigger than these:
but i can increase the height of immage to increase the character and make it more readable: How can I increase the distance between the horizontal bars and then increase the font size?
Any advice to make the red line more visible
To guarantee the colors will be assigned in the desired way, you'll need to insert some 'fake' data into your dataset right before you plot it. This way it will have both colorvars in the data, even if both colors are not shown in the plot...
data fake_data;
Area_commerciale=''; colorvar=1; output;
Area_commerciale=''; colorvar=2; output;
run;
data pga2007; set pga2007 fake_data;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.