- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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 .
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 .
Thank you again
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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 .
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.