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

I have the below proceedure.  I have sorted the x axis variable in decending order, it shows in the correct descending order in the dataset.  However when I run the Proc Template and subsequent Proc Sgrender steps the x axis is resorted in ascending order.  How can I keep the descending order.  Thank you.

PROC SORT DATA=WORK.ALLUP_PIPEHIST OUT=WORK.ALLUP_PIPEHIST1;

BY DESCENDING TIME_REF ;

FORMAT Pipe_Ct comma8.;

RUN;

*create bar chart of pipeline;

title;

footnote;

PROC TEMPLATE;

DEFINE STATGRAPH Pipe_App_Disp;

begingraph / DATACOLORS=(blue grey);

entrytitle 'Pipe / App / Disp History';

layout overlay / xaxisopts=(display=(ticks tickvalues))

yaxisopts=(griddisplay=off);

barchart x=TIME_REF y=Pipe_Ct /group=SOURCE stat=sum

GROUPDISPLAY=STACK dataskin=crisp BARWIDTH=.5 BARLABEL=TRUE BARLABELATTRS=(color=black weight=bold );

discretelegend 'a' / TITLE='Source:';

endlayout;

endgraph;

end;

run;

PROC SGRENDER DATA=WORK.ALLUP_PIPEHIST1 TEMPLATE=Pipe_App_Disp;

RUN;

1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Use the REVERSE option on the XAXISOPTS:

 

xaxisopts=(reverse=true)

 

To further elaborate:

 

When you use numeric data on a discrete axis (such as this bar chart case), the data is automatically forced to be in ascending numeric order. To make it descend, it is easiest to just use the REVERSE option. It is technically possible to create a string column containing the formatted numeric values, which will be rendered in DATA order (retaining your sort); but, for your case, using REVERSE is simpler.

 

Thanks!
Dan

View solution in original post

3 REPLIES 3
DanH_sas
SAS Super FREQ

Use the REVERSE option on the XAXISOPTS:

 

xaxisopts=(reverse=true)

 

Hope this helps!

Dan

DanH_sas
SAS Super FREQ

Use the REVERSE option on the XAXISOPTS:

 

xaxisopts=(reverse=true)

 

To further elaborate:

 

When you use numeric data on a discrete axis (such as this bar chart case), the data is automatically forced to be in ascending numeric order. To make it descend, it is easiest to just use the REVERSE option. It is technically possible to create a string column containing the formatted numeric values, which will be rendered in DATA order (retaining your sort); but, for your case, using REVERSE is simpler.

 

Thanks!
Dan

BLarson
Obsidian | Level 7

Once again you have helped me tremendously.  I greatly appreciate your insights.  This worked perfectly.  You are going on my Christmas card list!!

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
  • 3 replies
  • 3139 views
  • 3 likes
  • 2 in conversation