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
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;
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;
Or for datetime values something like:
'10NOV05:00:00:00'dt
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.
Is your input data in your X axis column in DATE or DATETIME format (not the column format, but the actual values)?
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.
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;
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;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.