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

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


100percent.png
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

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

9 REPLIES 9
suraestar
Calcite | Level 5

Hi,

Thanks.

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

data_null__
Jade | Level 19

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.

Jay54
Meteorite | Level 14

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

Jay54
Meteorite | Level 14

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;

suraestar
Calcite | Level 5

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.

data_null__
Jade | Level 19

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;
suraestar
Calcite | Level 5

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?

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
  • 9 replies
  • 4282 views
  • 4 likes
  • 4 in conversation