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;
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
Use the REVERSE option on the XAXISOPTS:
xaxisopts=(reverse=true)
Hope this helps!
Dan
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
Once again you have helped me tremendously. I greatly appreciate your insights. This worked perfectly. You are going on my Christmas card list!!
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!
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.
Ready to level-up your skills? Choose your own adventure.