I would like assign superscripts to LSMEANS differences from multiple comparison tests.
I have different factors with 2-3-4 and 5 levels to be used.
Below an example with 5 treatments and the desired output. Different letters meaning significant difference.
Thanks in advance
Trt | _Trt | Probz | Adjp | Desired output |
| |
1 | 2 | 0.0043 | 0.043 | Trt | superscripts | |
1 | 3 | 0.0572 | 0.5718 | 1 | acde | |
1 | 4 | 0.1636 | 1.0000 | 2 | b | |
1 | 5 | 0.0615 | 0.6146 | 3 | cb | |
2 | 3 | 0.5194 | 1.0000 | 4 | db | |
2 | 4 | 0.9288 | 1.0000 | 5 | ecd | |
2 | 5 | <0.0001 | 0.000 | |||
3 | 4 | 0,178 | 1.0000 | |||
3 | 5 | 0.8890 | 1.0000 | |||
4 | 5 | 0.4736 | 1.0000 |
This is one way to create such a value that will display in report:
ods escapechar='~'; data example; input super $; length str $ 50; str=cat('1','~{super ',super,'}'); datalines; a ab abc aef ; proc report data=example; columns str; define str / display; run;
The ODS escapechar sets a character that tells SAS that some commands involving appearance options will be used and the character will be followed by specific functions. Use something not commonly used in your programs for other puposeses. This character will need to be set for any session displaying these values. Make sure that your desired output value variable has spaces for the escapechar the braces { } the word super, the space, and the longest set of superscripts you expect to use.
Some warnings: It appears that frequently fonts are not defined with superscripts and may not display depending on the font used. It isn't impossible that some fonts display different characters than expected.
Other approaches could be used with adding UNICODE characters but I have so little success finding the actual code values that the SAS Unicode function, which might be the easiest way to build something, would want for specific values that I don't bother. If you attempt the unicode route your variable may need up to 5 or 6 "spaces" for each unicode character displayed.
Where exactly will these superscripts be displayed?
Not going to happen as the value in a data set so need some clue how you want to use this. Data set contents do not have any display properties such as super- or subscript, bold, underline, italic or what have you. Where they are to display can have a very significant effect on what needs to be done and possibly even the ODS destination(s) that are the target of these values.
It may also be necessary to have the rules involved in assigning these, especially since multiple values appear to be involved. Rule as in why does Trt=1 get acde and Trt=2 get b (and the others as well).
Thanks for your quick reply.
Please, you will find below another example with 5 trt. As previously mentioned, I would like to assign superscripts to identify if there are significant differences or not when comparing trt in 2x2 fashion. So in the example above (by the way the trt (1-5) are superscripted by the letters), trt 1-2 are not differentthey both have the same letter a. Trt 1-3 are different, so they have different letters (resp. a and c). Trt 1-4 are not different, so 4 has letter a as trt 1. Trt 1-5 are different so the have different letters (a vs. ecd). In this last cas, please note that the letters from trt 5 (ecd) come from other comparisons (2-5,3-5,4-5). Hope i made it clear. I would welcome any simple approach.
Thanks in advance.
Trt | _Trt | Estimation | Pr > |z| | P aj. | Desired output |
1 | 2 | 0.03443 | 0.9182 | 1.0000 | |
1 | 3 | -1.3209 | <.0001 | <.0001 | |
1 | 4 | -0.8055 | 0.0304 | 0.3037 | 1a |
1 | 5 | -1.4352 | <.0001 | <.0001 | 2ba |
2 | 3 | -1.3553 | <.0001 | 0.0001 | 3c |
2 | 4 | -0.8399 | 0.0320 | 0.3203 | 4dac |
2 | 5 | -1.4696 | <.0001 | 0.0001 | 5ecd |
3 | 4 | 0.5154 | 0.1380 | 1.0000 | |
3 | 5 | -0.1143 | 0.6834 | 1.0000 | |
4 | 5 | -0.6297 | 0.0891 | 0.8908 |
I repeat: Display Where? What procedure?
Approaches that might work in one procedure for a report may not work for a graph. The superscripting will not exist in a data set so cannot consider the "superscripting" as a modeling value.
This is one way to create such a value that will display in report:
ods escapechar='~'; data example; input super $; length str $ 50; str=cat('1','~{super ',super,'}'); datalines; a ab abc aef ; proc report data=example; columns str; define str / display; run;
The ODS escapechar sets a character that tells SAS that some commands involving appearance options will be used and the character will be followed by specific functions. Use something not commonly used in your programs for other puposeses. This character will need to be set for any session displaying these values. Make sure that your desired output value variable has spaces for the escapechar the braces { } the word super, the space, and the longest set of superscripts you expect to use.
Some warnings: It appears that frequently fonts are not defined with superscripts and may not display depending on the font used. It isn't impossible that some fonts display different characters than expected.
Other approaches could be used with adding UNICODE characters but I have so little success finding the actual code values that the SAS Unicode function, which might be the easiest way to build something, would want for specific values that I don't bother. If you attempt the unicode route your variable may need up to 5 or 6 "spaces" for each unicode character displayed.
Hi, your code was successful. Much appreciated.
I was looking for the logic on how to get the letters from p-values. Fortunately I found that the options were available under lsmeans lines linestable:
lsmeans &var / ilink cl diff ADJUST=BON lines linestable ;
ods output lsmeans=lsm LSMLines=LSMLines2;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.