BookmarkSubscribeRSS Feed
Ihsan-Mahdi
Quartz | Level 8

Hello,

I have a set containing 2 types of injuries (coded 0 & 1), and a date/time field. I'm interested in creating a heat map showing the frequency of occurrence of each injury type by time of day in a week, and another map showing frequency of occurrence by month of year.

Is that doable? If so, what would be the code?

This is a sample of my set:

data sample (compress=binary);
      INPUT record_id Injury1 Injury2 year InjuryDateTime:DATETIME20.; 
  format InjuryDateTime datetime20.;
      DATALINES;
2497728 1 0 2021 27APR2021:15:00:00
2590114 1 0 2023 25NOV2023:20:20:00
2590765 1 0 2023 18AUG2023:17:20:00
2590842 1 0 2023 06JUL2023:10:00:00
2591821 1 0 2023 16AUG2023:18:36:00
2591839 1 0 2023 31JUL2023:14:46:00
2591860 1 0 2023 04JUL2023:17:59:00
2599177 1 0 2023 01OCT2023:18:00:00
2599305 1 0 2023 01OCT2023:14:00:00
2600027 1 0 2023 22OCT2023:19:00:00
2600280 1 0 2023 22OCT2023:19:00:00
2502863 0 1 2021 13NOV2021:13:00:00
2507650 0 1 2021 24SEP2021:16:25:00
2507987 0 1 2021 12AUG2021:14:21:00
2508819 0 1 2021 07MAY2021:18:15:00
2516706 0 1 2021 21SEP2021:09:07:00
2516721 0 1 2021 20SEP2021:21:00:00
2516869 0 1 2021 05SEP2021:09:40:00
2517049 0 1 2021 14AUG2021:08:18:00
2517142 0 1 2021 05AUG2021:22:00:00
2517187 0 1 2021 31JUL2021:00:40:00
 
    ;
 
    RUN;
 
Thank you!
4 REPLIES 4
sbxkoenk
SAS Super FREQ

Let this paper be an inspiration:

 

Paper SAS4341-2016

Graph A Million with the SGPLOT Procedure

Prashant Hebbar and Sanjay Matange, SAS Institute Inc.

https://support.sas.com/resources/papers/proceedings16/SAS4341-2016.pdf

 

It's using the HEATMAP statement on numerous occasions.

In the third maintenance release of SAS 9.4 (SAS 9.4 M3), the SGPLOT procedure supports a HEATMAP statement. 

 

Koen

Ihsan-Mahdi
Quartz | Level 8

Thank you for responding. The referenced paper doesn't seem to contain a map similar to what I want, which would be something like this:

IhsanMahdi_3-1769466053936.png

 

Tom
Super User Tom
Super User

Did you try something like this?

data for_plot;
  set sample;
  day=weekday(datepart(InjuryDateTime));
  hour=hour(InjuryDateTime);
run;

proc sgplot;
  heatmap x=day y=hour / freq=Injury1;
run;
proc sgplot;
  heatmap x=day y=hour / freq=Injury2;
run;
Ihsan-Mahdi
Quartz | Level 8

I did, but the graphs comes up weird:

IhsanMahdi_0-1769468774376.png

I was hoping for Y axis labels of 0-23 and X axis labels of 1-7

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 107 views
  • 0 likes
  • 3 in conversation