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

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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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