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-2024.png

 

Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.

 

Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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