BookmarkSubscribeRSS Feed
somebody
Lapis Lazuli | Level 10

I would like to draw a graph that shows intraday price changes in several days. Each day trading hour is from 9am to 4pm. I have a date variable and a time variable. If I use these variables then there would be gaps between the days as there is no data between 4pm and 9 am the next day. One quick way I could overcome this is to use the order number _N_ but then I need to format the time axis to show the date and hour correctly. Is there a different and proper way to do this? thanks 

 

6 REPLIES 6
Jay54
Meteorite | Level 14

I addressed the "gap" issue in this blog article for holidays.  You can likely use the idea for your case.  I do not know of any format you can user to do this automatically.

 

https://blogs.sas.com/content/graphicallyspeaking/2017/09/27/stock-chart/

 

If a single axis is not a requirement, another way would be to use SGPANEL with PANELBY=day, and put the cells in a row.  Then, all the gaps between 4pm and 9am should go away.

 

somebody
Lapis Lazuli | Level 10

So I tried your suggested method but it gives an empty graph. my code is:

proc sgplot data=trade_summary2 noborder;

title "Intraday Effective Spread";
series x=datetime y=ES;

xaxis label= "Date" type=discrete discreteorder=data;
run;

I also changed type option to Time (type=TIME) but the gaps remain. 
datetime is a datetime variable
ballardw
Super User

I'm not sure if it would be worth the work depending on how many days you display at a time but the RANGES option could be used to create breaks. Use the date and time to create a datetime variable, use the desired format such as datetime10. and specify the ranges for each day which could be built from your data.

 

The break indicators might not be wanted but would at least indicate nothing is supposed to be in those intervals.

Reeza
Super User

I'd probably use the _n_ method and build a user defined format to show the dates the way you want. You can use CNTLIN to create the table that maps the _n_ to the date. 

 

somebody
Lapis Lazuli | Level 10

So I tried your suggestion and almost get there. my code is:

data datetimefmt; 
set trade_summary2; 
keep fmtname n datetime;
rename n=start datetime=label;
fmtname="datetimefmt";
run;

However, the display value is a long number, not in a datetime format that i need (i.e. 10Apr2018 09:30:15). What am I missing?

ballardw
Super User

@somebody wrote:

So I tried your suggestion and almost get there. my code is:

data datetimefmt; 
set trade_summary2; 
keep fmtname n datetime;
rename n=start datetime=label;
fmtname="datetimefmt";
run;

However, the display value is a long number, not in a datetime format that i need (i.e. 10Apr2018 09:30:15). What am I missing?


Most likely you want to use something like Label = put(datetime, datetime12.); to show values to hours.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1043 views
  • 3 likes
  • 4 in conversation