BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PaigeMiller
Diamond | Level 26

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;

Capture.PNG

--
Paige Miller
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

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;

Ksharp_0-1634651232787.png

 

View solution in original post

10 REPLIES 10
djrisks
Barite | Level 11

Hi @PaigeMiller, if you make the output size larger or the axis tick values smaller, then all the axis tick values can be displayed.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
djrisks
Barite | Level 11

Also perhaps use the VALUESROTATE=VERTICAL option.

PaigeMiller
Diamond | Level 26
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;

Capture.PNG

 

Still not what I want 😞

--
Paige Miller
djrisks
Barite | Level 11

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;

PaigeMiller
Diamond | Level 26

And how to I get the format I want (yyq4.) with TYPE=DISCRETE?

--
Paige Miller
Ksharp
Super User

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;

Ksharp_0-1634651232787.png

 

PaigeMiller
Diamond | Level 26

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 🙂

--
Paige Miller
Ksharp
Super User
Maybe this could work out .

xaxis values=('01JAN1980'd to '01JAN1987'd by quarter)
label="Year/Quarter" valuesformat=yyq4. interval=quarter fitpolicy=rotate;
yabwon
Onyx | Level 15

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.

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 2432 views
  • 6 likes
  • 4 in conversation