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;
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;
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;
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.)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.