Data visualization with SAS programming

How to create 100 percent stacked Bar chart using GTL?

Accepted Solution Solved
Reply
Contributor
Posts: 46
Accepted Solution

How to create 100 percent stacked Bar chart using GTL?

Hi ,

I want to generate a 100 percent stacked Bar chart using GTL Code?

PFA attachment for the expected output from GTL.

Can anyone help me in setting up the code ?

Thanks

Attachment

Accepted Solutions
Solution
‎04-22-2014 06:12 AM
Respected Advisor
Posts: 3,768

Re: How to create 100 percent stacked Bar chart using GTL?

You have to make the data summary with the percent calculated within each group first.

proc sort data=sashelp.cars out=cars;
   by origin;
   run;
proc freq data=cars noprint;
  
by origin;
   tables type / out=g100;
   run;
proc print;
  
run;
proc template;
  
define statgraph bar100;
      begingraph;
        
layout overlay;
           
BARCHARTPARM X = origin y=percent / group=type;
            endlayout;
        
endgraph;
     
end;
  
run;
proc sgrender data=g100 template=bar100;
   run;

View solution in original post


All Replies
Respected Advisor
Posts: 3,768

Re: How to create 100 percent stacked Bar chart using GTL?

In 's blog he uses SGPLOT but I reckon you can do the same with GTL.

http://blogs.sas.com/content/graphicallyspeaking/2014/04/06/g100-with-sgplot/

Contributor
Posts: 46

Re: How to create 100 percent stacked Bar chart using GTL?

Hi,

Thanks.

But I want the options\statment in PROC TEMPLATE.... BARCHART statement..? Not using SGPLOT or GCHART.

Respected Advisor
Posts: 3,768

Re: How to create 100 percent stacked Bar chart using GTL?

RTM.  I did not intend to "like" your reply but I don't know how to "unlike".:smileyplain:

TMPLOUT=“filename

writes the Graph Template Language code for your graph to a file.

SAS Super FREQ
Posts: 1,044

Re: How to create 100 percent stacked Bar chart using GTL?

Due to its popularity, an option to do a "G100" like bar chart will be added to GTL and SG procedures soon. 

SAS Super FREQ
Posts: 1,044

Re: How to create 100 percent stacked Bar chart using GTL?

Just  an FYI...

Dan just reminded me that G100 feature has been added to SGPLOT procedure with SAS 9.4.  User PCTLEVEL=GROUP;

sgplot data=sashelp.cars pctlevel=group;

  vbar origin / group=type stat=pct;

  run;

Grand Advisor
Posts: 9,320

Re: How to create 100 percent stacked Bar chart using GTL?

Contributor
Posts: 46

Re: How to create 100 percent stacked Bar chart using GTL?

Hi All,

Thanks for your replies.

The below is the code which I tried to generate 100% stacked bar chart without Y axis and below is the output which I got.output.PNG

proc template;
define statgraph bar100;
begingraph;
   layout overlay;
    barchart x=Origin /group=type
       stat=pct;
   endlayout;
  endgraph;
end;
run;

ods rtf file="c:temp\bar100.rtf";
proc sgrender data=sashelp.cars template=bar100;
run;
ods rtf close;

My expected Output is

100percent.png

Please suggest me how to generate since I am new to SAS graph.

Thanks.

Solution
‎04-22-2014 06:12 AM
Respected Advisor
Posts: 3,768

Re: How to create 100 percent stacked Bar chart using GTL?

You have to make the data summary with the percent calculated within each group first.

proc sort data=sashelp.cars out=cars;
   by origin;
   run;
proc freq data=cars noprint;
  
by origin;
   tables type / out=g100;
   run;
proc print;
  
run;
proc template;
  
define statgraph bar100;
      begingraph;
        
layout overlay;
           
BARCHARTPARM X = origin y=percent / group=type;
            endlayout;
        
endgraph;
     
end;
  
run;
proc sgrender data=g100 template=bar100;
   run;
Contributor
Posts: 46

Re: How to create 100 percent stacked Bar chart using GTL?

Hi,


I have one doubt.

Is it possible to give in BARCHART statement? or Do we need to use BARCHARTPARM ?

Does it make any difference in output since we are paasing the summarized data to the erender?

Post a Question
Discussion Stats
  • 9 replies
  • 1315 views
  • 3 likes
  • 4 in conversation