I want year/quarter on the XAXIS, but the values on the axis is somehow "thinned" so only quarters 1 and 3 of each year are shown. I want all quarters (not just 1 and 3) to show, so the tick marks would be labelled 80Q1 80Q2 80Q3 80Q4 etc., and I want the values to either be diagonal or rotated, but I can't seem to get it right. I'm sure I'm missing something simple. Tell me what I'm doing wrong. Thanks!
proc sgplot data=sashelp.citiqtr(where=('01JAN1980'd<=date<'01JAN1987'd));
series x=date y=bpb;
xaxis label="Year/Quarter" valuesformat=yyq4. interval=quarter fitpolicy=rotate;
run;
Here is my code. Did you miss some date in sashelp.citiqtr ?
data have; do date='01JAN1980'd to '01JAN1987'd ; bpb=1; output; end; proc sgplot data=have; series x=date y=bpb; xaxis values=('01JAN1980'd to '01JAN1987'd by quarter) type=linear label="Year/Quarter" valuesformat=yyq4. fitpolicy=rotate; run;
Hi @PaigeMiller, if you make the output size larger or the axis tick values smaller, then all the axis tick values can be displayed.
I don't think that's the answer. I just tried it with
ods graphics/height=9in width=12in;
and nothing changed as far as the x-axis tick marks and values.
Also, even at the size I showed, you should be able to turn the x-axis text to squeeze more tick marks and their values in.
Also perhaps use the VALUESROTATE=VERTICAL option.
proc sgplot data=sashelp.citiqtr(where=('01JAN1980'd<=date<'01JAN1987'd));
series x=date y=bpb;
xaxis values=('01JAN1980'd to '01JAN1987'd by quarter) label="Year/Quarter" valuesformat=yyq4. interval=quarter valuesrotate=vertical;
run;
Still not what I want 😞
This example uses vertical x-axis tick values:
proc sgplot data=sashelp.revhub2;
scatter x=hub y=revenue / group=type groupdisplay=cluster clusterwidth=0.5;
xaxis type=discrete valuesrotate=vertical fitpolicy=rotate valueattrs=(size=12);
run;
And how to I get the format I want (yyq4.) with TYPE=DISCRETE?
Here is my code. Did you miss some date in sashelp.citiqtr ?
data have; do date='01JAN1980'd to '01JAN1987'd ; bpb=1; output; end; proc sgplot data=have; series x=date y=bpb; xaxis values=('01JAN1980'd to '01JAN1987'd by quarter) type=linear label="Year/Quarter" valuesformat=yyq4. fitpolicy=rotate; run;
Okay, @Ksharp that works! I see that TYPE=LINEAR is somehow required to produce the desired x-axis, although I'm not sure why. Nevertheless, I can just remember to use TYPE=LINEAR from now on, and everyone here will be smiling 🙂
something like that worked for me:
data test;
set sashelp.citiqtr(where=('01JAN1980'd<=date<'01JAN1987'd));;
format date yyq6.;
keep date bpb;
run;
proc sgplot data=test;
series x=date y=bpb;
xaxis label="Year/Quarter" interval=quarter fitpolicy=rotate
TYPE=DISCRETE VALUESROTATE=VERTICAL
;
run;
B.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.