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!!
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.