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

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!

xliu1_0-1614375450471.png

 

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

@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!

xliu1_0-1614375450471.png

 

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.

View solution in original post

3 REPLIES 3
ballardw
Super User

@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!

xliu1_0-1614375450471.png

 

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.

xliu1
Quartz | Level 8

Thanks. It works out perfectly!

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 3102 views
  • 0 likes
  • 3 in conversation