BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mgarret
Obsidian | Level 7

Hi--

I'm new to using SAS graph and I am trying to program a couple group bar charts.  I have attached an example of  of what I'm trying to accomplish (Chart Example.xlsx

I have a data set  which looks like this:

yearMonthPILOT_CATEGORYMEDIA_METHODTouch_count
2014FebruaryControlDirect Mail14096
2014FebruaryTestDirect Mail49801
2014FebruaryControlEmail811743
2014FebruaryTestEmail745799
2014MarchControlDirect Mail255563
2014MarchTestDirect Mail202191
2014MarchControlEmail1101510
2014MarchTestEmail563655

This is what I have for syntax so far -  which is not the desired output I'm looking for.

proc gchart data=have;

  vbar Touch_count / group= PILOT_CATEGORY

                            patternid=group;

  vbar Touch_count / subgroup=Month;

run;

quit;

Again, an example of what I'm looking for is attached.  Any assistance is greatly appreciated.  Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Since you're using sas/graph gchart in your code, here's how to do it in gchart...

data have;
INFILE DATALINES DLM=',';
length month pilot_category media_method $20;
input year Month PILOT_CATEGORY MEDIA_METHOD Touch_count;
datalines;
2014,February,Control,Direct Mail,14096
2014,February,Test,Direct Mail,49801
2014,February,Control,Email,811743
2014,February,Test,Email,745799
2014,March,Control,Direct Mail,255563
2014,March,Test,Direct Mail,202191
2014,March,Control,Email,1101510
2014,March,Test,Email,563655
;
run;

proc sort data=have out=have;
by media_method;
run;

options nobyline;
title1 ls=1.5 "Marketing Touches Results: #byval(media_method)";

axis1 label=none major=(number=7) minor=none offset=(0,0);
axis2 label=none value=none;
axis3 label=none offset=(8,8);

legend1 label=(position=top color=white) position=(bottom center)
shape=bar(.15in,.15in);

pattern1 v=r color=red;
pattern2 v=s color=red;

goptions device=png xpixels=500 ypixels=400 gunit=pct htitle=4.0 htext=3.2;


proc gchart data=have;
by media_method;
format touch_count comma10.0;
vbar pilot_category / type=sum sumvar=touch_count legend=legend1
group=month subgroup=pilot_category outside=sum
width=15 space=0 gspace=8 coutline=same
raxis=axis1 maxis=axis2 gaxis=axis3 noframe
autoref clipref cref=graycc;
run;

And here are the 2 graphs the above code produces -- pretty much exactly like the ones in your excel spreadsheet...

foo1.png

foo2.png

View solution in original post

6 REPLIES 6
Jay54
Meteorite | Level 14

You can use the SGPLOT procedure to get similar graphs.  While SAS graphics has its own defaults, you can get this look with some options.

DirectMail.png

EMailJournal.png

GraphGuy
Meteorite | Level 14

Since you're using sas/graph gchart in your code, here's how to do it in gchart...

data have;
INFILE DATALINES DLM=',';
length month pilot_category media_method $20;
input year Month PILOT_CATEGORY MEDIA_METHOD Touch_count;
datalines;
2014,February,Control,Direct Mail,14096
2014,February,Test,Direct Mail,49801
2014,February,Control,Email,811743
2014,February,Test,Email,745799
2014,March,Control,Direct Mail,255563
2014,March,Test,Direct Mail,202191
2014,March,Control,Email,1101510
2014,March,Test,Email,563655
;
run;

proc sort data=have out=have;
by media_method;
run;

options nobyline;
title1 ls=1.5 "Marketing Touches Results: #byval(media_method)";

axis1 label=none major=(number=7) minor=none offset=(0,0);
axis2 label=none value=none;
axis3 label=none offset=(8,8);

legend1 label=(position=top color=white) position=(bottom center)
shape=bar(.15in,.15in);

pattern1 v=r color=red;
pattern2 v=s color=red;

goptions device=png xpixels=500 ypixels=400 gunit=pct htitle=4.0 htext=3.2;


proc gchart data=have;
by media_method;
format touch_count comma10.0;
vbar pilot_category / type=sum sumvar=touch_count legend=legend1
group=month subgroup=pilot_category outside=sum
width=15 space=0 gspace=8 coutline=same
raxis=axis1 maxis=axis2 gaxis=axis3 noframe
autoref clipref cref=graycc;
run;

And here are the 2 graphs the above code produces -- pretty much exactly like the ones in your excel spreadsheet...

foo1.png

foo2.png

Mgarret
Obsidian | Level 7

Thanks Robert! This is perfect. I appreciate it.

Mgarret
Obsidian | Level 7

Hi Robert--

I have another questions if you have time.  I am trying to incorporate the charts into a report - see my program below.  I have  to include a table and both charts in one page. Is it possible that  I can shrink the charts and have them side by side horizontally?  Any assistance will be greatly appreciated

proc sort data=touches_month_chart out=touches_month_chart;

by media_method;

run;

ods listing;

options leftmargin=".1 in" topmargin=".1 in"

        rightmargin=".1 in" bottommargin=".1 in"

        nodate nonumber orientation=portrait;

ods pdf file="U:\Matt Local\Programs\VLSS Programs\Report.pdf"

startpage=yes;

ods escapechar='^';

footnote;

/*This creates a table from another dataset*/

proc report

data=touches_month_table nowd headline headskip

style(column)={just=c font_size=11pt font_face= 'Arial Narrow' /*cellwidth=2.5in*/}

style(header)={font_size=11 pt font_face= 'Arial Narrow' FONT_WEIGHT =BOLD background=cxcccccc};

title1 "^S={font_face='Arial Narrow' font_weight=bold font_size=14pt}

Marketing Touches";

column ("^S={font_face='Arial Narrow' FONT_WEIGHT =BOLD background=CXDC143C just=c font_size=12pt} Frequency of Marketing Touches by Month ^S={}"  Month MEDIA_METHOD  Control Test);

define Month / group

style(column)={just=l cellwidth=.8in bordertopcolor=black borderrightcolor=black borderlefttcolor=black borderbottomcolor=black};

define MEDIA_METHOD / display

style(column)={just=l cellwidth=1in  bordertopcolor=black borderrightcolor=black borderlefttcolor=black borderbottomcolor=black};

define Control / display

style(column)={just=c cellwidth=.7in bordertopcolor=black borderrightcolor=black borderlefttcolor=black borderbottomcolor=black};

define Test / display

style(column)={just=c cellwidth=.7in bordertopcolor=black borderrightcolor=black borderlefttcolor=black borderbottomcolor=black};

run;

ods pdf startpage=no;

options nobyline;

title1 ls=1.5 "Marketing Touches Results: #byval(media_method)";

axis1 label=none major=(number=7) minor=none offset=(0,0);

axis2 label=none value=none;

axis3 label=none offset=(8,8);

legend1 label=(position=top color=white) position=(bottom center)

shape=bar(.15in,.15in);

pattern1 v=r color=red;

pattern2 v=s color=red;

goptions device=png xpixels=500 ypixels=400 gunit=pct htitle=4.0 htext=3.2;

proc gchart data=touches_month_chart;

by media_method;

format touch_count comma10.0;

vbar pilot_category / type=sum sumvar=touch_count legend=legend1

group=month subgroup=pilot_category outside=sum

width=10 space=0 gspace=8 coutline=same

raxis=axis1 maxis=axis2 gaxis=axis3 noframe

autoref clipref cref=graycc;

run;

title;

ods _all_ close;

ods listing;

GraphGuy
Meteorite | Level 14

Sorry, but I don't know too much about generating pdf output with graphs.

If you don't get an answer on the forum, that might be a good question to send to Tech Support Smiley Happy

Andre
Obsidian | Level 7

Mgarret

You can take an idea from my contribution in

https://communities.sas.com/message/205231#205231

The program place a top area and then 2 maps side by side

and then again 2 areas with maps

So the trick is to remain on the same page

and the adjust your vsize hsize vorigin and horign goptions

HTH

Andre

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
  • 6 replies
  • 1540 views
  • 3 likes
  • 4 in conversation