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;
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.)
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.
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.