BookmarkSubscribeRSS Feed
anurak
Fluorite | Level 6

I am trying to create a graph like below using scatter and series plot. I am not able to place blocks like below. This graph is temperature display over time which is from vital signs and block is from AE table where each block display AE start and end day.

 

anurak_0-1674499974938.png

 

 

I tried with highlowplot, but I am not getting what I expected . Please help me to find solution for this complicated graph

anurak_1-1674499974929.png

 

 

4 REPLIES 4
ballardw
Super User

Typically SAS requires the data of the basic plot elements to be in a single data set. Your description makes it seem like you have two data sets involved. Is that in fact the case.

 

Please provide some example data in the form of a data step. We can't code with pictures as a data source.

 

It might not hurt to show the code you have attempted as that way would at least have variable names to talk about.

 

Here is a very basic block chart with series data:

data example;
   do x='01Jan2023'd to '15Mar2023'd;
      y= rand('integer',10);
      if '03Jan2023'd <=x <='10Jan2023'd then blockvar='Block 1';
      else if '11Jan2023'd <=x <='22Jan2023'd then blockvar='Block 2';
      else if x>'23Feb2023'd then blockvar='Block 3';
      output;
   end;
   format x date9.;
run;

proc sgplot data=example;
   block x=x block=blockvar;
   series x=x y=y;
run;

You may have to include "blocks" that have no obvious fill but without more example I'm not going to bother.

Different options for fillattrs and transparency may require additional work.

anurak
Fluorite | Level 6

proc template;
 define statgraph scatplot;
 begingraph /;
 layout overlay;
 seriesplot y=temp_c x=vsdy / name='mutation';
 scatterplot y=temp_c x=vsdy;

highlowplot y=temp_c high=aeendy low=aestdy/highlabel =term fillattrs=(color=red) type=bar barwidth=0.4
 discretelegend 'mutation';
 endlayout;
 endgraph;
 end;
run;

 

for records from AE, i hardcoded value temp_c to 100, so bar will be in the top

subjid vsdy temp_c AESTDY AEENDY term
1 0 97.34      
1 1 98.6      
1 4 99.14      
1 7 98.78      
1 10 96.26      
1 14 97.88      
1 21 98.24      
1 28 98.24      
1 42 98.24      
1 53 98.24      
1   100 7 10 CRS
1   100 19 25 CRS
 
ballardw
Super User

Use the BLOCKPLOT statement instead of HIGHLOWPLOT.

This page in the documentation https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/grstatgraph/n0ifwefyk3jw1fn1rjcdz5jfakiw.htm  has an Example 1 that is basically what you are attempting.

 

Your existing data may need some help to look more like the example though as you currently have no X variable values associated with your Block values, which I think is your Term variable. That issue about the X variable is also why the Highlowplot didn't even come close.

Any plots to overlay require use of a common X variable (for horizontal base plots, if the base is the Y axis like an HBAR or HBOX then common Y variable is required).

anurak
Fluorite | Level 6

Can I use bandplot?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 761 views
  • 0 likes
  • 2 in conversation