cancel
Showing results for 
Search instead for 
Did you mean: 

In respect to SGPLOT VBAR

SOLVED
Cingchih
Quartz | Level 8
Solved!

In respect to SGPLOT VBAR

Message contains an image Message contains an attachment

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

 

 

Attachment
Download this attachment
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisNZ
Tourmaline | Level 20
Solution

Re: In respect to SGPLOT VBAR

Message contains an image

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
Solution

Re: In respect to SGPLOT VBAR

Message contains an image

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

Re: In respect to SGPLOT VBAR

Cingchih
Quartz | Level 8

Re: In respect to SGPLOT VBAR

Message contains an image

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

Re: In respect to SGPLOT VBAR

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

Re: In respect to SGPLOT VBAR

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

 

Highlighted
ChrisNZ
Tourmaline | Level 20

Re: In respect to SGPLOT VBAR

Message contains a hyperlink

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

Re: In respect to SGPLOT VBAR

Message contains a hyperlink Message contains an image

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

Re: In respect to SGPLOT VBAR

Cingchih
Quartz | Level 8

Re: In respect to SGPLOT VBAR

finish updating.