I have some data recorded for financial years with some years missing. I would like to plot this with the x-axis properly scaled. What is the best way to do this? For example, in the program below, the distance between the 2001-02 and 2002-03 tick marks are the same as the distance between the 2002-03 and 2009-10 marks. I would like to scale them appropriately. Is there an axis scaling option that does this?
data test; input y year $; datalines; 1 2001-02 5 2002-03 3 2009-10 ; run; proc sgplot data=test; series y=y x=year /markers; run;
Take a look at the XAXIS statement to control which VALUES that will appear on the axsis and the VALUESFORMAT on how to display the dates. You can use syntax like values = ('01Jan2000'd to '01Jan2011'd by month) to get monthly tick marks. The YYMMd7. format will display dates as yyyy-mm.
The range of your example data is such that if you display every month on the axis then your tick marks may get crowded or too busy depending on the current graphics display area. You may need to adjust that with the ODS Graphics/ width= option.
I need the labels to be "2001-02" etc rather than standard SAS date markers. However, building on the values option, I think the following code does the trick. (I've run the axis out to 2020 to check that the "fitpolicy=thin" option works).
It would be more elegant if SAS had an output format that mapped a SAS date to a fiscal year string of this type. That way SAS would recognise that the axis is a date axis and apply defaults accordingly.
* PlotTest.sas; data test; input y year $; datalines; 1 2001-02 5 2002-03 3 2009-10 ; run; %macro fyvaluesq(start,end); %* e.g %fyvaluesq(2001,2004) => "2001-02" "2002-03" "2003-04" Used in sgplot for fin year plots; %let output=; %do y1 = &start %to %eval(&end-1); %let y2 = %substr(%eval(&y1+1),3,2); %let output=&output %bquote(")&y1-&y2%bquote("); %end; %unquote(&output) %mend; proc sgplot data=test; series y=y x=year /markers; xaxis values=(%fyvaluesq(2001,2020)) fitpolicy=thin; run;
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.