Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- Add a vertical reference line to time series plot in sas

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 02-26-2021 04:41 PM
(2507 views)

I try to add a vertical reference line to a time series plot to indicate the year where the forecast starts, but keep getting this error message in sas log. The variable AY has the datetime format Year4. The sas code works for the plot until I add the refline statement. Will appreciate any help with the refline statement! Thanks!

```
PROC SGPLOT DATA=BACHDEG_Forecast;
BAND Upper=u95 Lower=l95 x=AY / Legendlabel="95% Confidence Limits";
scatter x=AY y=degrees_usf;
series x=AY y=forecast;
refline "AY=2022" / axis=x lineattrs=(thickness=1 color=BLUE pattern=dash);
RUN;
```

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@xliu1 wrote:

I try to add a vertical reference line to a time series plot to indicate the year where the forecast starts, but keep getting this error message in sas log. The variable AY has the datetime format Year4. The sas code works for the plot until I add the refline statement. Will appreciate any help with the refline statement! Thanks!

`PROC SGPLOT DATA=BACHDEG_Forecast; BAND Upper=u95 Lower=l95 x=AY / Legendlabel="95% Confidence Limits"; scatter x=AY y=degrees_usf; series x=AY y=forecast; refline "AY=2022" / axis=x lineattrs=(thickness=1 color=BLUE pattern=dash); RUN;`

REFLINE wants either a VARIABLE or an explicit Value that is associated with the Axis.

So one of

refline AY / <options>;

or

refline 2022 /<options>;

"AY=2022" would only be valid if the value "AY=2022" appears on your x axis, meaning the axis would be character valued.

If the axis is a date value then you would use a date literal value like "01JAN2022"d to provide a date. If you haven't used date literals before they **must** be in the Date9 (better) or Date7 appearance, in quotes, with the d immediately following the value.

3 REPLIES 3

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@xliu1 wrote:

I try to add a vertical reference line to a time series plot to indicate the year where the forecast starts, but keep getting this error message in sas log. The variable AY has the datetime format Year4. The sas code works for the plot until I add the refline statement. Will appreciate any help with the refline statement! Thanks!

`PROC SGPLOT DATA=BACHDEG_Forecast; BAND Upper=u95 Lower=l95 x=AY / Legendlabel="95% Confidence Limits"; scatter x=AY y=degrees_usf; series x=AY y=forecast; refline "AY=2022" / axis=x lineattrs=(thickness=1 color=BLUE pattern=dash); RUN;`

REFLINE wants either a VARIABLE or an explicit Value that is associated with the Axis.

So one of

refline AY / <options>;

or

refline 2022 /<options>;

"AY=2022" would only be valid if the value "AY=2022" appears on your x axis, meaning the axis would be character valued.

If the axis is a date value then you would use a date literal value like "01JAN2022"d to provide a date. If you haven't used date literals before they **must** be in the Date9 (better) or Date7 appearance, in quotes, with the d immediately following the value.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks. It works out perfectly!

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Ready to level-up your skills? Choose your own adventure.