Data visualization with SAS programming

How to create the bar chart for my requirement using proc gchart?

Reply
Contributor
Posts: 46

How to create the bar chart for my requirement using proc gchart?

[ Edited ]

I have attached input dataset sample that has values for the bar chart and I have also attached the wanted barchart sample.

In the bar chart , I need find out from 2007 to 2010, how many times(frequency) GY1, GY2 and GY3 are ranked in each year (shown as numbers under bars on the graph attached). And within each year’s bars I’d also like to know what the proportions are respectively that GY1, GY2 and GY3 are ranked as 1st, 2nd and 3rd (shown as percentages within each bars).

 

 

Super User
Posts: 19,160

Re: How to create the bar chart for my requirement using proc gchart?

Please consider adding data and image directly to your post. Not everyone can download attachments. 

SAS Super FREQ
Posts: 706

Re: How to create the bar chart for my requirement using proc gchart?

[ Edited ]

Hi

 

Not exactly the graph your are looking for, but it is a start, and it has all the information you are looking for. I have used Proc SGPANEL instead of Proc GCHART.

 

data have;  
  infile cards dlm=",";
  input
    Year
    Ranking
    Group_Y_Name $ 
    cnt_gy_name
  ;
  cards;
2007,1,GY1,2
2007,2,GY1,1
2007,1,GY2,2
2007,2,GY2,2
2007,1,GY3,1
2007,2,GY3,1
2007,3,GY3,1
2008,1,GY1,1
2008,2,GY1,1
2008,3,GY1,1
2008,1,GY2,1
2008,2,GY2,2
2008,1,GY3,1
2008,3,GY3,1
2009,2,GY1,3
2009,3,GY1,1
2009,1,GY2,4
2009,1,GY3,1
2009,2,GY3,1
2009,3,GY3,1
2010,1,GY1,2
2010,2,GY1,2
2010,1,GY2,4
2010,2,GY2,1
2010,1,GY3,1
2010,2,GY3,3
;

proc sgpanel data=have pctlevel=group;
  styleattrs
    datacolors=(cxfddcbb cxaddfe6 cxf5f8c9)
    datacontrastcolors=(cxfddcbb cxaddfe6 cxf5f8c9)
  ;
  panelby Group_Y_Name / 
    layout=columnlattice 
    colheaderpos=bottom
    novarname
    noborder
      
  ;
  vbar year / 
    response=cnt_gy_name
    group=Ranking stat=percent
    seglabel seglabelformat=percent9.
  ;
  colaxistable  cnt_gy_name;

  keylegend / noborder  TITLE=" ";
run;

Bruno

Contributor
Posts: 46

Re: How to create the bar chart for my requirement using proc gchart?

@Bruno_SAS Very nice Sir, Thank you so much. That pretty much did it for me. It seems like you have loads of experience in SAS. How did you manage to read, understand and remember all these options. Is there a method or technique to learn SAS more effectively? I would welcome your suggestions plz

SAS Super FREQ
Posts: 706

Re: How to create the bar chart for my requirement using proc gchart?

[ Edited ]

Allaluiah

 

If you are new to SAS, it is worthwhile to attend a SAS Training course, to get all the fundamental concepts right. This makes reading the code examples you will find everywhere a lot easier.

 

For all things related to ODS Graphics I suggest you follow the blog http://blogs.sas.com/content/graphicallyspeaking/ by @Sanjay_SAS it has lots and lots of great examples and tips and tricks on how to best use ODS Graphics.

 

For SAS/GRAPH read the blogs entries from  @RobertAllison_SAS  http://blogs.sas.com/content/sastraining/author/robertallison/ one can only wonder what is possible.

 

The thing is, one has to remember. But since there is always a story around it, this makes it a lot easier, at least for me.

 

Bruno

 

 

Ask a Question
Discussion stats
  • 4 replies
  • 524 views
  • 0 likes
  • 3 in conversation