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

Hello , 

So i'm trying to get a clustered bar chart from my data using proc gchart , but I can't get it all to work.

I'm trying to compare the two prices ( Ask price and buy price ) for every maturity grouped by date.

My data is like this : 

 

Date         |       Maturity     |        ask_Price     |       buy_Price

01jan                    1                           50                           20 

01jan                    2                         600                         250

01jan                    5                         376                         120

02jan                    6                         500                           20 

02jan                    4                           60                           30

02jan                    7                           37                           12

   .                         .                             .                              .

   .                         .                             .                              .  

 

So for a specific date , there may be different maturities, and for every maturity I have Ask and buy price.

For the bar chart ,  I want to group it by date , and the subgroup should be maturity.

so for every date I should have the traded maturities in that date , and for every maturity I should have the ask_price and buy_price.

 

Thank you in advance for your help

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@LoPez_Diaz wrote:

Thank you for your fast reply , 

What I need is a side by side clustered bar chart.

the date is the group variable , the maturity is the subgroup variable , but i don't know how to display the ask and buy price for  every maturity.

Please check the link to see a similar graph, except that for every pop_group in the linked graph , I should have two bars .

 

https://www.bing.com/images/search?view=detailV2&id=1493CDA15CD560DD31ED183198374474E69F446F&thid=OI...

 

Thank you again


That example shows two grouping variables, region and population.

In effect your example data has three grouping variables: week, maturity and ask/buy type + a value.

 

One of the examples from the same source: https://www.bing.com/images/search?view=detailV2&id=66EE8198E271BFBD4C87EA526EDD1EC296B08434&thid=OI...

or simpler:  https://blogs.sas.com/content/graphicallyspeaking/2013/09/07/bar-charts-with-stacked-and-cluster-gro...

shows and SGPANEL result. Adding the groupdisplay=cluster should get you close.

BUT the data needs to be in the correct structure which means a single value(price) to plot and an additional variable to indicate which type of price the value represents.

 

data have;
 input Date $      Maturity  $        ask_Price           buy_Price ;
datalines;
01jan      1      50         20 
01jan      2    600       250
01jan      5    376       120
02jan      6    500         20 
02jan      4     60         30
02jan      7     37         12
;
run;

data need;
   set have;
   type='Ask'; Price=Ask_price; output;
   type='Buy'; price=Buy_price; output;
run;

proc sgpanel data=need;
  panelby date / layout=columnlattice novarname noborder colheaderpos=bottom;
  vbar maturity / response=price group=Type groupdisplay=cluster ;
  rowaxis grid;
run;

View solution in original post

6 REPLIES 6
LoPez_Diaz
Obsidian | Level 7

I used this code , but I only get one price to show up, either buy or ask price ... 

how can I get both to show up ? 

 

proc sgplot data=work.'levée_trésor'n;
vbar date / group = maturity groupdisplay=cluster response=buy_price;
run;

 

Thank you 

ballardw
Super User
proc sgplot data=work.'levée_trésor'n;
   vbar date / group = maturity groupdisplay=cluster response=buy_price;
   vbar date / group = maturity groupdisplay=cluster response=ask_price;
run;

should display something with both variables.

 

I'm not quite sure what you are wanting though

LoPez_Diaz
Obsidian | Level 7

Thank you for your fast reply , 

What I need is a side by side clustered bar chart.

the date is the group variable , the maturity is the subgroup variable , but i don't know how to display the ask and buy price for  every maturity.

Please check the link to see a similar graph, except that for every pop_group in the linked graph , I should have two bars .

 

https://www.bing.com/images/search?view=detailV2&id=1493CDA15CD560DD31ED183198374474E69F446F&thid=OI...

 

Thank you again

ballardw
Super User

@LoPez_Diaz wrote:

Thank you for your fast reply , 

What I need is a side by side clustered bar chart.

the date is the group variable , the maturity is the subgroup variable , but i don't know how to display the ask and buy price for  every maturity.

Please check the link to see a similar graph, except that for every pop_group in the linked graph , I should have two bars .

 

https://www.bing.com/images/search?view=detailV2&id=1493CDA15CD560DD31ED183198374474E69F446F&thid=OI...

 

Thank you again


That example shows two grouping variables, region and population.

In effect your example data has three grouping variables: week, maturity and ask/buy type + a value.

 

One of the examples from the same source: https://www.bing.com/images/search?view=detailV2&id=66EE8198E271BFBD4C87EA526EDD1EC296B08434&thid=OI...

or simpler:  https://blogs.sas.com/content/graphicallyspeaking/2013/09/07/bar-charts-with-stacked-and-cluster-gro...

shows and SGPANEL result. Adding the groupdisplay=cluster should get you close.

BUT the data needs to be in the correct structure which means a single value(price) to plot and an additional variable to indicate which type of price the value represents.

 

data have;
 input Date $      Maturity  $        ask_Price           buy_Price ;
datalines;
01jan      1      50         20 
01jan      2    600       250
01jan      5    376       120
02jan      6    500         20 
02jan      4     60         30
02jan      7     37         12
;
run;

data need;
   set have;
   type='Ask'; Price=Ask_price; output;
   type='Buy'; price=Buy_price; output;
run;

proc sgpanel data=need;
  panelby date / layout=columnlattice novarname noborder colheaderpos=bottom;
  vbar maturity / response=price group=Type groupdisplay=cluster ;
  rowaxis grid;
run;
LoPez_Diaz
Obsidian | Level 7

Hello , 

Thank you again for your help ... I really appreciate .

The code you gave me works great , but I get multiple pages in output. Every date has its own bar graph showing the ask and buy.

Is there a way to get all the dates in the same graph ? 
Thank you very much

ballardw
Super User

Look at the options for the Panelby statement. The option ONEPANEL will attempt to place the entire graph in a single panel. But if you have lots of values of DATE you may run into issues with not being able to show them all across one row.

 

Which may lead to the options about rows and columns settings.

sas-innovate-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1505 views
  • 1 like
  • 2 in conversation