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

I'm using sgplot and am trying to add a reference line for a certain month (march 2020) when I have the x-axis variable formated as yymmn6. However, using this sample code I get the following warning:

WARNING: X='202003' is invalid. The plot will not be drawn.  Which gives me the plot, without the reference line. How do I formulate the refline statement to get my line to show up?

data test;
input monthno count;
datalines;
202001 78
202002 67
202003 99
202004 56
202005 63
202006 82
;
run;

data test;
set test;
time=input(put(monthno,6.),yymmn6.);
format time yymmn6.;
run;

proc sgplot data= test;
	yaxis label="Amount";
	xaxis label="Month";
	series x=time y=count;
	refline '202003' /axis=x;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
Try;


refline '1mar2020'd /axis=x;

View solution in original post

5 REPLIES 5
Ksharp
Super User
Try;


refline '1mar2020'd /axis=x;
PaigeMiller
Diamond | Level 26

You can't specify a character variable value in this case for the X axis, which is numeric. You need to specify a numeric value, which in this case is 01MAR2020

 

refline '01MAR2020'd /axis=x;
--
Paige Miller
PeterClemmensen
Tourmaline | Level 20

Use a Date Constant

 

proc sgplot data= test;
	yaxis label="Amount";
	xaxis label="Month";
	series x=time y=count;
	refline "01mar2020"d /axis=x;
run;
FreelanceReinh
Jade | Level 19

Hello @AnkaS and welcome to the SAS Support Communities!

 

My first thought was also to specify a date literal or other numeric value, but it turned out that your formatted value '202003' works better if you add the option type=discrete to the XAXIS statement:

xaxis label="Month" type=discrete;

Without this option the x-axis tick mark labels did not even honor the YYMMN6. format in my SAS session, but were displayed in an "automatically generated" format, as a note in the log said.

 

(Edit: Changing the axis type to "discrete" would of course change the appearance of the graph if the monthno values weren't equidistant.)

AnkaS
Calcite | Level 5
Thank you, all. That solved it.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1081 views
  • 1 like
  • 5 in conversation