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

Hello,

 

I can't seem to get the right order in my legend. my variables are coded in order that I want it to show

0=<80

1=80-90

2=>90

and the reference category is <80 but this is the plot I get:

 

SASnewbiee_1-1594135720054.png

 

It still has the order:  80-90, <80 , >90

and I want <80, 80-90, >90

 

 

My code used: (I tried to mess with ODS graphics but I couldn't understand)

 

proc logistic data=sbb descending plots=effect;
class finalcat3(ref='<80%');
model score= ugpa finalcat3/rsq lackfit cl;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
class finalcat3(ref='<80%' order=internal);

This forces SAS to use the internal order (0, 1, 2) when ordering the levels in the output.

--
Paige Miller

View solution in original post

6 REPLIES 6
PaigeMiller
Diamond | Level 26

@SASnewbiee wrote:

Hello,

 

I can't seem to get the right order in my legend. my variables are coded in order that I want it to show

0=<80

1=80-90

2=>90

and the reference category is <80 but this is the plot I get:

 

SASnewbiee_1-1594135720054.png

 

It still has the order:  80-90, <80 , >90

and I want <80, 80-90, >90


Character variables will have their values sorted alphabetically by default. That's what you are seeing. In general, you want to leave numeric variables as numeric variables, because numeric variables sort numerically (that's what you want) and then apply a custom format to them so they appear as 80-90, or as <80, or as >90.

--
Paige Miller
SASnewbiee
Fluorite | Level 6
Yes, without the format it was 0, 1, 2 in the order I want. But then I tried to format within the proc logistic step and have the same problem.

Is there no way to have that format, and in the order I need?
PaigeMiller
Diamond | Level 26

Show me your code.

--
Paige Miller
SASnewbiee
Fluorite | Level 6
data sbb; set sbb;
label finalcat3="Final Exam";
run;

proc format;
value fin 0="<80%"
1="80-90%"
2=">90%";
value sc 0=Failed
1=Passed;
run;

proc logistic data=sbb descending plots=effect;
class finalcat3(ref='0');
model score= ugpa finalcat3/rsq lackfit cl;

format finalcat3 fin. score sc.;
run;
PaigeMiller
Diamond | Level 26
class finalcat3(ref='<80%' order=internal);

This forces SAS to use the internal order (0, 1, 2) when ordering the levels in the output.

--
Paige Miller
SASnewbiee
Fluorite | Level 6
This worked, thank you very much!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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