turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- how to subset data for a graph so that lines are n...

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

03-27-2012 01:26 PM

I have the following example which produces the attached graph. How do I alter the code so that in the output the orange and green bars are not stacked but rather one in front of the other?

thanks a ton!

**data** test;

input bucket date:mmddyy10. pct group $;

datalines;

1 11/01/2011 2 Study

1 12/01/2011 3 Study

1 01/01/2012 2 Study

1 11/01/2011 3 Base

1 12/01/2011 5 Base

1 01/01/2012 3 Base

2 11/01/2011 6 Study

2 12/01/2011 3 Study

2 01/01/2012 4 Study

2 11/01/2011 3 Base

2 12/01/2011 7 Base

2 01/01/2012 2 Base

;

**run**;

**PROC** **GCHART** DATA=WORK.test;

format date mmyyd7.;

VBAR3d

date

/ discrete

SUMVAR=pct

group=bucket

subgroup=group

CLIPREF

FRAME TYPE=SUM

COUTLINE=BLACK

;

**RUN**; **QUIT**;

Accepted Solutions

Solution

03-27-2012
01:43 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASguyCO

03-27-2012 01:43 PM

This is relatively straightforward with SGPLOT. Here is the code and output. You can modify it to suit.

data test;

input bucket date:mmddyy10. pct group $;

datalines;

1 11/01/2011 2 Study

1 12/01/2011 3 Study

1 01/01/2012 2 Study

1 11/01/2011 3 Base

1 12/01/2011 5 Base

1 01/01/2012 3 Base

2 11/01/2011 6 Study

2 12/01/2011 3 Study

2 01/01/2012 4 Study

2 11/01/2011 3 Base

2 12/01/2011 7 Base

2 01/01/2012 2 Base

;

run;

/*--Transpose grouped data into multi-variable--*/

data multiVar;

keep Study Base date;

format date mmddyy10.;

merge test(where=(group="Study") rename=(pct=Study))

test(where=(group="Base") rename=(pct=Base));

run;

proc print; run;

ods listing gpath='C:\Work\Blogs\Communities\images';

ods graphics / reset width=5in height=3in imagename='BarOverlay'

title 'Percent by Study';

proc sgplot data=multivar;

vbar date / response=base nostatlabel;

vbar date / response=study nostatlabel barwidth=0.7 transparency=0.1;

yaxis label='Pct';

xaxis display=(nolabel);

run;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASguyCO

03-27-2012 01:38 PM

Getting bars to appear as though they're in-front/behind each other (rather than stacked or side-by-side) is a bit tricky in SAS/Graph (not really one of the built-in features of Gchart).

Here is an example that you might like to look at, that uses annotate to draw the overlapping bars:

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

03-27-2012 01:42 PM

Is it simpler to have it done side by side? Doesn't need to be one in front of the other, just not stacked.

Solution

03-27-2012
01:43 PM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASguyCO

03-27-2012 01:43 PM

This is relatively straightforward with SGPLOT. Here is the code and output. You can modify it to suit.

data test;

input bucket date:mmddyy10. pct group $;

datalines;

1 11/01/2011 2 Study

1 12/01/2011 3 Study

1 01/01/2012 2 Study

1 11/01/2011 3 Base

1 12/01/2011 5 Base

1 01/01/2012 3 Base

2 11/01/2011 6 Study

2 12/01/2011 3 Study

2 01/01/2012 4 Study

2 11/01/2011 3 Base

2 12/01/2011 7 Base

2 01/01/2012 2 Base

;

run;

/*--Transpose grouped data into multi-variable--*/

data multiVar;

keep Study Base date;

format date mmddyy10.;

merge test(where=(group="Study") rename=(pct=Study))

test(where=(group="Base") rename=(pct=Base));

run;

proc print; run;

ods listing gpath='C:\Work\Blogs\Communities\images';

ods graphics / reset width=5in height=3in imagename='BarOverlay'

title 'Percent by Study';

proc sgplot data=multivar;

vbar date / response=base nostatlabel;

vbar date / response=study nostatlabel barwidth=0.7 transparency=0.1;

yaxis label='Pct';

xaxis display=(nolabel);

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

03-27-2012 01:54 PM

You the man Sanjay! thanks so much. that's very easy and helpful!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASguyCO

03-27-2012 01:59 PM

Note, you do need SAS 9.2 or later version to use SG procedures.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

03-27-2012 02:30 PM

Robert pointed out I did not use the 'Bucket' variable. You can retain it in the data, and either use BY statement in SGPLOT (for separate graphs), or use SGPANEL and PANELBY Bucket to get both buckets in the same graph.

With SAS 9.3, you can use a GROUP variable with GROUPDISPLAY=CLUSTER as another option. or you can use DISCRETEOFFSET to be more creative. With SAS 9.3, you also have the DataSkin option to spiffy up the appearance. See recent blog article.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

03-27-2012 02:59 PM

I'm using EG 4.3

Sanjay, can you provide example syntax for using the sgpanel and the panelby commands?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

03-27-2012 02:30 PM

Or, how to do it with Gchart (if you don't have 9.2).

data test;

input bucket date:mmddyy10. pct group $;

datalines;

1 11/01/2011 2 Study

1 12/01/2011 3 Study

1 01/01/2012 2 Study

1 11/01/2011 3 Base

1 12/01/2011 5 Base

1 01/01/2012 3 Base

2 11/01/2011 6 Study

2 12/01/2011 3 Study

2 01/01/2012 4 Study

2 11/01/2011 3 Base

2 12/01/2011 7 Base

2 01/01/2012 2 Base

;

run;

axis1 label=none value=none;

proc gchart data=test;

by bucket;

format date mmddyy10.;

vbar group / maxis=axis1

type=sum sumvar=pct subgroup=group

group=date gspace=5 space=0;

run;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

03-27-2012 02:59 PM

This is good to Robert, but I'd rather have it all on one graph as opposed to separate graphs for each bucket.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to SASguyCO

03-27-2012 03:11 PM

data test;

input bucket date:mmddyy10. pct group $;

datalines;

1 11/01/2011 2 Study

1 12/01/2011 3 Study

1 01/01/2012 2 Study

1 11/01/2011 3 Base

1 12/01/2011 5 Base

1 01/01/2012 3 Base

2 11/01/2011 6 Study

2 12/01/2011 3 Study

2 01/01/2012 4 Study

2 11/01/2011 3 Base

2 12/01/2011 7 Base

2 01/01/2012 2 Base

;

run;

/*--Transpose grouped data into multi-variable--*/

data multiVar;

keep bucket Study Base date;

format date mmddyy10.;

merge test(where=(group="Study") rename=(pct=Study))

test(where=(group="Base") rename=(pct=Base));

run;

proc print; run;

ods listing gpath='C:\Work\Blogs\Communities\images';

ods graphics / reset width=5in height=3in imagename='BarOverlayPlot';

title 'Percent by Study';

proc sgplot data=multivar;

by bucket;

vbar date / response=base nostatlabel;

vbar date / response=study nostatlabel barwidth=0.7 transparency=0.1;

yaxis label='Pct';

xaxis display=(nolabel);

run;

ods graphics / reset width=5in height=3in imagename='BarOverlayPanel';

title 'Percent by Study';

proc sgpanel data=multivar;

panelby bucket / onepanel columns=2;

vbar date / response=base nostatlabel;

vbar date / response=study nostatlabel barwidth=0.7 transparency=0.1;

rowaxis label='Pct';

colaxis display=(nolabel);

run;