The simplest way is to set your labels to be numbers in the order you want to see them, and then apply a format to the labels so they show the text, e.g.:
proc format; value temp 1="Value 2" 2="Value 3" 3="Value 1"; run; data have; set have; if lab="Value 2" then labn=1; ...; format labn temp.; run;
Then use labn as your labels, this will sort by the number, and display the test per the format.
thanks for the help, It unfortunately didn't work with your suggestions, I probably might have made a mistake some where in the code but I finally found a very easy way to solve the problem.
the issue is that I wanted to sort the listed items in my keylegend. Not using ascending or descending order as used in Sortorder (the Keylegend Statement).
I solved the problem this way: since I have set the order already in my attrmap while assigning colors to the bars. I just added an extra column to my attrmap which is Show = "Attrmap"
this displays the legend items in the order which is defined in the Attrmap for a example if you assign colors this way using attrmap
input id $ value $10. @19 fillcolor $8. show $10.;
flavor Vanilla beige attrmap
flavor Chocolate cx663D29 attrmap
flavor Strawberry pink attrmap
this will display the items in your legend in this order vanilla, Chocolate, Strawberry
Great solution, Anita!
A related tip:
When using the SHOW and NOCASE columns, I usually RETAIN the values for the attrmap, as you can have only one value for these columns per map. Using RETAIN helps simplify the data step a bit:
retain show "attrmap";
input id $ value $10. @19 fillcolor $8.;
flavor Vanilla beige
flavor Chocolate cx663D29
flavor Strawberry pink
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.