Data visualization with SAS programming

SGPLOT Refline

Accepted Solution Solved
Reply
Contributor CEG
Contributor
Posts: 25
Accepted Solution

SGPLOT Refline

Hi,

 

I'm having a problem creating 2 reference lines.  

 

The input for my X Axis looks like Datetime7:   01JUL15  through  30DEC16.

SGPLOT replaces Datetime7 with an auto-generated format.   It looks like:

 

Jul      Sep    Nov    Jan     Mar  May Jul  ........................ Jan

2015                       2016                                                   2017

 

 

How do I create reference lines at 08FEB16 and 17MAR16?

 

I get errors when I use the numerics for those dates, use the actual Datetime7 dates, and when I just ask for FEB or MAR.

 

Thanks for any help you can give.

CEG


Accepted Solutions
Solution
‎02-23-2017 05:56 PM
SAS Super FREQ
Posts: 3,615

Re: SGPLOT Refline

As we said earlier, use the literal datetime constants. See if this helps:

 

data a;
format x datetime20.;
do x = '01JUL2015:00:00:00'DT to '3DEC2016:00:00:00'DT by 1e6;
   y = 3 + sin(x/2e7);
   output;
end;

proc sgplot data=A;
series x=x y=y;
refline '08FEB2016:00:00:00'DT  '17MAR2016:00:00:00'DT / axis=x;
run;

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,615

Re: SGPLOT Refline

Use the date literals:

'08FEB2016'D  and  '17MAR2016'D

For example:

 

proc sgplot data=sashelp.stocks;
series x=date y=close / group=stock;
refline '08FEB1993'D '17MAR2000'D / axis=X;
run;
Super User
Posts: 11,101

Re: SGPLOT Refline

Or for datetime values something like:

'10NOV05:00:00:00'dt

 

 

 

 

Contributor CEG
Contributor
Posts: 25

Re: SGPLOT Refline

By adding the 00:00:00, it gave me the 17MAR16 line; but it didn't create the 08FEB16 line.



The auto-generation gives me every other month which excludes FEB. Is there a way to override that?



Thanks!


SAS Super FREQ
Posts: 925

Re: SGPLOT Refline

You can use the INTERVAL option on the XAXIS statement to override the internally-determined time interval; however, since the time axis is continuous, the presence or absense of the FEB tick value should not affect the placement of the REFLINE.

Contributor CEG
Contributor
Posts: 25

Re: SGPLOT Refline

Thanks!



Can you think of anything else that could cause the FEB line to be ignored?


SAS Super FREQ
Posts: 925

Re: SGPLOT Refline

Is your input data in your X axis column in DATE or DATETIME format (not the column format, but the actual values)?

Contributor CEG
Contributor
Posts: 25

Re: SGPLOT Refline

I format the numeric values into Datetime7.






SAS Super FREQ
Posts: 925

Re: SGPLOT Refline

I needed to know the RAW format of the input date, not the final formatted value. The reason I ask is that it might make a difference on whether you should specify the refline value as '01jan2016'd (Rick) or '01jan2016:00:00:00'dt (ballardw). You want the refline value to match the other raw values used on the axis.

SAS Super FREQ
Posts: 3,615

Re: SGPLOT Refline

To do what Dan asks,  remove the format and use PROC PRINT to see the raw values:

 

/* replace the name of the dat set with YOUR name */
proc print data=sashelp.timedata(OBS=3);
format datetime;   /* <== put the name of YOUR variable here */
var datetime;        /* <== and here */
run;
Contributor CEG
Contributor
Posts: 25

Re: SGPLOT Refline

I'm sorry. Thanks for everyone's help.



The "numerics" I was talking about are 10 digits. That's why adding the 00:00:00 worked for at least the March date. The format was 7.



Here they are: 1751377219 1751420561 1751432207


Solution
‎02-23-2017 05:56 PM
SAS Super FREQ
Posts: 3,615

Re: SGPLOT Refline

As we said earlier, use the literal datetime constants. See if this helps:

 

data a;
format x datetime20.;
do x = '01JUL2015:00:00:00'DT to '3DEC2016:00:00:00'DT by 1e6;
   y = 3 + sin(x/2e7);
   output;
end;

proc sgplot data=A;
series x=x y=y;
refline '08FEB2016:00:00:00'DT  '17MAR2016:00:00:00'DT / axis=x;
run;

Contributor CEG
Contributor
Posts: 25

Re: SGPLOT Refline

Thanks! I almost got it. This helped. Have to make a few adjustments.


☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 784 views
  • 1 like
  • 4 in conversation