BookmarkSubscribeRSS Feed
zhangda
Fluorite | Level 6

 

Hello,

 

I have the code below showing a two curve outlay on bar chart, but I need some changes. First, how to add a vertial line on the right side of the graph corresponding to the vertical line on the left side that shows the percentage ranging  0% to 100%. Second, for the final graph, how to add a small box filled with a small piece of bar shape and  colored corresponding to the bar color? also,  to add a small box filled with a small piece of line shape and  colored corresponding to the line? The small boxes should be  placed  ahead of d_2015, d_2016, d_2015_2, d_2016_2 , so that the readers would understand by first sight, that the bars are for d_2015, d_2016 and the lines are for d_2015_2, d_2016_2. Thank you so much! 

 

data ds1;

input year $ mid $ resp1 resp2;

mid2=cat(strip(mid), "_2");

datalines;

null d_2016 0.45 0.64

null d_2015 0.35 0.783

s_300 d_2016 0.65 0.67

s_300 d_2015 0.55 0.75

s_640 d_2016 0.42 0.89

s_640 d_2015 0.65 0.87

s_670 d_2016 0.35 0.12

s_670 d_2015 0.75 0.09

s_700 d_2016 0.83 0.06

s_700 d_2015 0.47 0.07

s_730 d_2016 0.48 0.18

s_730 d_2015 0.58 0.21

s_760 d_2016 0.67 0.05

s_760 d_2015 0.69 0.045

;

run;

/*--Define Attr Map for groups--*/

data attrmap;

length value FillColor LineColor TextColor $12;

Id='X'; Value="d_2015"; FillStyleElement='graphdata1'; LineStyleElement='graphdata1'; TextStyleElement='graphdata1';output;

Id='X'; Value="d_2016"; FillStyleElement='graphdata2'; LineStyleElement='graphdata2'; TextStyleElement='graphdata2';output;

Id='X'; Value="d_2015_2"; FillStyleElement='graphdata3'; LineStyleElement='graphdata3'; TextStyleElement='graphdata3';output;

Id='X'; Value="d_2016_2"; FillStyleElement='graphdata4'; LineStyleElement='graphdata4'; TextStyleElement='graphdata4';output;

run;

ods listing gpath='.' image_dpi=200;

ods graphics / reset attrpriority=color width=5in height=3in imagename='Goodgraph';

title 'Score Distribution';

proc sgplot data=ds1 noborder noautolegend cycleattrs dattrmap=attrmap;

vbarparm category=year response=resp1 / group=mid groupdisplay=cluster

outlineattrs=(color=black) barwidth=0.8 attrid=X;

series x=year y=resp2 / group=mid2 smoothconnect attrid=X

lineattrs=(thickness=3);

xaxistable resp1 / class=mid colorgroup=mid attrid=X;

xaxistable resp2 / class=mid2 colorgroup=mid2 attrid=X;

xaxis display=(nolabel) label="Year";

yaxis offsetmin=0 label="Rate" tickvalueformat= percent7.0;

run;

2 REPLIES 2
zhangda
Fluorite | Level 6

 

Hello,

 

I have the code below showing a two curve outlay on bar chart, but I need some changes. First, how to add a vertial line on the right side of the graph corresponding to the vertical line on the left side that shows the percentage ranging  0% to 100%. Second, for the final graph, how to add a small box filled with a small piece of bar shape and  colored corresponding to the bar color? also,  to add a small box filled with a small piece of line shape and  colored corresponding to the line? The small boxes should be  placed  ahead of d_2015, d_2016, d_2015_2, d_2016_2 , so that the readers would understand by first sight, that the bars are for d_2015, d_2016 and the lines are for d_2015_2, d_2016_2. Thank you so much! 

 

 

data ds1;

input year $ mid $ resp1 resp2;

mid2=cat(strip(mid), "_2");

datalines;

null d_2016 0.45 0.64

null d_2015 0.35 0.783

s_300 d_2016 0.65 0.67

s_300 d_2015 0.55 0.75

s_640 d_2016 0.42 0.89

s_640 d_2015 0.65 0.87

s_670 d_2016 0.35 0.12

s_670 d_2015 0.75 0.09

s_700 d_2016 0.83 0.06

s_700 d_2015 0.47 0.07

s_730 d_2016 0.48 0.18

s_730 d_2015 0.58 0.21

s_760 d_2016 0.67 0.05

s_760 d_2015 0.69 0.045

;

run;

/*--Define Attr Map for groups--*/

data attrmap;

length value FillColor LineColor TextColor $12;

Id='X'; Value="d_2015"; FillStyleElement='graphdata1'; LineStyleElement='graphdata1'; TextStyleElement='graphdata1';output;

Id='X'; Value="d_2016"; FillStyleElement='graphdata2'; LineStyleElement='graphdata2'; TextStyleElement='graphdata2';output;

Id='X'; Value="d_2015_2"; FillStyleElement='graphdata3'; LineStyleElement='graphdata3'; TextStyleElement='graphdata3';output;

Id='X'; Value="d_2016_2"; FillStyleElement='graphdata4'; LineStyleElement='graphdata4'; TextStyleElement='graphdata4';output;

run;

ods listing gpath='.' image_dpi=200;

ods graphics / reset attrpriority=color width=5in height=3in imagename='Goodgraph';

title 'Score Distribution';

proc sgplot data=ds1 noborder noautolegend cycleattrs dattrmap=attrmap;

vbarparm category=year response=resp1 / group=mid groupdisplay=cluster

outlineattrs=(color=black) barwidth=0.8 attrid=X;

series x=year y=resp2 / group=mid2 smoothconnect attrid=X

lineattrs=(thickness=3);

xaxistable resp1 / class=mid colorgroup=mid attrid=X;

xaxistable resp2 / class=mid2 colorgroup=mid2 attrid=X;

xaxis display=(nolabel) label="Year";

yaxis offsetmin=0 label="Rate" tickvalueformat= percent7.0;

run;

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

 

For what I can make out are your two questions:

"how to add a vertial line on the right side" - check out YAXIS2 in the SAS guidance, that is the right hand axis, same as XAXIS2 for the top one.

"to add a small box filled with a small piece of line shape" - these are called legends, you can find many examples of these in the documentation, just set your legend to the graph part you need.

 

If you require further help with graphs, take a look at:

http://blogs.sas.com/content/graphicallyspeaking/

Lots of great examples on all graphs.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 859 views
  • 0 likes
  • 2 in conversation