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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

12 REPLIES 12
Rick_SAS
SAS Super FREQ

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;
ballardw
Super User

Or for datetime values something like:

'10NOV05:00:00:00'dt

 

 

 

 

CEG
Calcite | Level 5 CEG
Calcite | Level 5
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!


DanH_sas
SAS Super FREQ

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.

CEG
Calcite | Level 5 CEG
Calcite | Level 5
Thanks!



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


DanH_sas
SAS Super FREQ

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

CEG
Calcite | Level 5 CEG
Calcite | Level 5
I format the numeric values into Datetime7.






DanH_sas
SAS Super FREQ

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.

Rick_SAS
SAS Super FREQ

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;
CEG
Calcite | Level 5 CEG
Calcite | Level 5
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


Rick_SAS
SAS Super FREQ

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;

CEG
Calcite | Level 5 CEG
Calcite | Level 5
Thanks! I almost got it. This helped. Have to make a few adjustments.


Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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