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

Hi Team, 

Do you know any sample sgprot codes draw candle stick charts with volume information?
I found some only for prices in candle stick but don't see codes including volume information at the bottom of the chart.

sashelp.stocks as the example.

 

Thank you,

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

There is an example here: http://support.sas.com/kb/35/040.html

that starts with the SASHELP.STOCKS data set that may get you started.

 

You don't explain in your PDF what the difference may be between the red and green elements so can't make any suggestions.

View solution in original post

6 REPLIES 6
Reeza
Super User

Rough idea is here:

 

/*--Extract one stock, set group and add caps based on Open > Close--*/
data stock;
  length Gain $4 lowcap highcap $12;
  set sashelp.stocks(where=(stock='IBM' and date > '01Jan2003'd));
  
  if open < close then do;
    gain='Up';
    v1=open; v2=close;
    lowcap='';
    highcap='FilledArrow';
  end; 
  else do; 
    gain='Down'; 
    v1=close; v2=open;
    lowcap='FilledArrow';
    highcap='';
  end;
run;

proc template;
    define statgraph needleVolume;
        begingraph / collation=binary;
        EntryTitle "Monthly Stock Price" /;
        layout gridded / columns=1 rows=2 rowgutter=5 columngutter=5;
        layout overlay / xaxisopts=(display=(ticks tickvalues line) type=time) 
            y2axisopts=(labelFitPolicy=Split) yaxisopts=(Label="Price" 
            labelFitPolicy=Split type=linear griddisplay=on) 
            y2axisopts=(labelFitPolicy=Split);
        HighLowPlot X=Date High=High Low=Low / primary=true LegendLabel="HighLow" 
            NAME="HIGHLOW";
        HighLowPlot X=Date High=v2 Low=v1 / type=bar Group=COLOR_GAIN 
            OutLineAttrs=(Color=CX000000) LegendLabel="HighLow" NAME="a";
        DiscreteLegend "a" / Location=Inside valign=bottom;
        endlayout;
        layout overlay / yaxisopts=(labelFitPolicy=Split) 
            y2axisopts=(labelFitPolicy=Split);
        NeedlePlot X=Date Y=Volume / primary=true LegendLabel="Volume" NAME="NEEDLE";
        endlayout;
        endlayout;
        endgraph;
    end;
run;

proc sgrender template=needleVolume data=stock;
run;

@k_shide wrote:

Hi Team, 

Do you know any sample sgprot codes draw candle stick charts with volume information?
I found some only for prices in candle stick but don't see codes including volume information at the bottom of the chart.

sashelp.stocks as the example.

 

Thank you,

 


Here's the reference to the SGTEMPLATE documentation

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatug&docsetTarget=tit...

k_shide
Obsidian | Level 7

Thank you very much. I understand the idea.

Actually R provides quite powerful charting procedure as attached pdf file and if SAS also could do that's great but seems to require more complicated template creation right?

 

Jay54
Meteorite | Level 14
You can create a Candle Stick chart using the HighLow statement in SGPLOT
procedure. Some data step processing may be needed to create the
appropriate columns. I will try to build an example.
Reeza
Super User
ggplot2 is pretty powerful but I'm not sure I'd say the template creation is more complicated. It's defining your own template and then the automation is pretty straightforward but I didn't attempt to make it pretty or anything, I'll leave that to you.
ballardw
Super User

There is an example here: http://support.sas.com/kb/35/040.html

that starts with the SASHELP.STOCKS data set that may get you started.

 

You don't explain in your PDF what the difference may be between the red and green elements so can't make any suggestions.

k_shide
Obsidian | Level 7
Thank you this is what I want. Didn't make it clear but volume and price must be perfectly aligned so that I can compare them.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 975 views
  • 4 likes
  • 4 in conversation