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

Hi everyone,

I am having issue with vbar statement of Proc SGPLOT. Here is data.

 

A room:

    case 1 from 2018/1/1 8:00 am to 2018/1/1 9:30 am

    case 2 from 2018/1/1 9:50 am to 2018/1/1 10:20 am

    case 3 from 2018/1/1 10:50 am to 2018/1/1 2:50 pm

 

B room:

    case 1 from 2018/1/1 8:45 am to 2018/1/1 11:20 am

    case 2 from 2018/1/1 11:55 am to 2018/1/1 4:20 pm

 

Please help to get the plot. Thank you.

Page0002.jpg

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20

You may have to use annotations.

data GRAPH;
  ROOM=1; CASE=1; TIME='01jan2018:08:00'dt; output; TIME='01jan2018:09:30'dt; output; 
  ROOM=1; CASE=2; TIME='01jan2018:09:50'dt; output; TIME='01jan2018:10:20'dt; output;
  ROOM=1; CASE=3; TIME='01jan2018:10:50'dt; output; TIME='01jan2018:14:50'dt; output;
  ROOM=2; CASE=1; TIME='01jan2018:08:45'dt; output; TIME='01jan2018:11:20'dt; output;
  ROOM=2; CASE=2; TIME='01jan2018:11:55'dt; output; TIME='01jan2018:16:20'dt; output;
  format TIME  datetime.;
run;

data ANNO;
  retain X1SPACE Y1SPACE 'datavalue' FUNCTION 'rectangle' FILLCOLOR 'lightblue' HEIGHTUNIT 'data' ANCHOR 'bottom' WIDTH 5 DISPLAY 'all';
  set GRAPH;
  by ROOM CASE;
  X1=ROOM; Y1=lag(TIME); HEIGHT=dif(TIME);
  if last.CASE;
run;

proc format ;
  value room 1='A' 2='B';
run;

proc sgplot data=GRAPH sganno=ANNO;
 scatter X=ROOM Y=TIME / markerattrs=(color=white);
 xaxis offsetmin=.25 offsetmax=.25 type=discrete ;
 refline TIME / lineattrs=(color=verylightgray);
 format ROOM room.;
run;
  

Capture.PNG

 

View solution in original post

9 REPLIES 9
ChrisNZ
Tourmaline | Level 20

You may have to use annotations.

data GRAPH;
  ROOM=1; CASE=1; TIME='01jan2018:08:00'dt; output; TIME='01jan2018:09:30'dt; output; 
  ROOM=1; CASE=2; TIME='01jan2018:09:50'dt; output; TIME='01jan2018:10:20'dt; output;
  ROOM=1; CASE=3; TIME='01jan2018:10:50'dt; output; TIME='01jan2018:14:50'dt; output;
  ROOM=2; CASE=1; TIME='01jan2018:08:45'dt; output; TIME='01jan2018:11:20'dt; output;
  ROOM=2; CASE=2; TIME='01jan2018:11:55'dt; output; TIME='01jan2018:16:20'dt; output;
  format TIME  datetime.;
run;

data ANNO;
  retain X1SPACE Y1SPACE 'datavalue' FUNCTION 'rectangle' FILLCOLOR 'lightblue' HEIGHTUNIT 'data' ANCHOR 'bottom' WIDTH 5 DISPLAY 'all';
  set GRAPH;
  by ROOM CASE;
  X1=ROOM; Y1=lag(TIME); HEIGHT=dif(TIME);
  if last.CASE;
run;

proc format ;
  value room 1='A' 2='B';
run;

proc sgplot data=GRAPH sganno=ANNO;
 scatter X=ROOM Y=TIME / markerattrs=(color=white);
 xaxis offsetmin=.25 offsetmax=.25 type=discrete ;
 refline TIME / lineattrs=(color=verylightgray);
 format ROOM room.;
run;
  

Capture.PNG

 

ChrisNZ
Tourmaline | Level 20
Cingchih
Quartz | Level 8

Thank you for your reply.

The date range for room A is from 01Jan2018 08:00 to 01Jan2018 14:50.

However, I find that it is incorrect label on the y axis.see red region. 

Please help me. Thank you in advance.

 

 

圖片 008.png

ChrisNZ
Tourmaline | Level 20

It is not incorrect, it is rounded to the closest hour.

I cant test in the next while, but there may be a restriction on the label length. 

I'll look further tomorrow if you haven't found a way. 

 

Cingchih
Quartz | Level 8

We can use the format (e.g., 1Jan 8:00 and 1Jan 14:50, even 8:00 and 14:50). Thank you very much.

 

ChrisNZ
Tourmaline | Level 20

You can do this by creating you own format.

Sadly there is no dttime format.

 

See how to do this here (from page 14) and the reference is here.

 

Cingchih
Quartz | Level 8

I got it.

 

proc sgplot data=GRAPH sganno=ANNO ;
scatter X=ROOM Y=TIME / markerattrs=(color=white) ;
xaxis offsetmin=.25 offsetmax=.25 type=discrete ;
yaxis interval=minute;       /* increase the syntax  */  
format ROOM room. ; 
run;

 

 ref:

http://morgan.dartmouth.edu/Docs/sas92/support.sas.com/documentation/cdl/en/grstatproc/61948/HTML/de...

 

SGPlot26.png

ChrisNZ
Tourmaline | Level 20
Cingchih
Quartz | Level 8
finish updating.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 9 replies
  • 2200 views
  • 2 likes
  • 2 in conversation