BookmarkSubscribeRSS Feed
AnaVelloso
Calcite | Level 5

I have a set of data where I am doing a Tukey's test. I woud like to change the order of how it showing in my graphs, placing first ,<12, 12, 13-15, 16 and >16. Any tip of how I can change this? 

 

ods graphics on;
proc glm data = incomes plots =diagnostics;
class Educ;
model Income2005=Educ ;
lsmeans Educ/stderr pdiff=all adjust=tukey;
run;

Boxplot.jpg

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Sort your data by Educ and use Order=Data in the PROC GLM Statement like this

 

proc sort data=sashelp.iris out=test1;
   by descending Species;
run;

proc glm data=test1 plots=diagnostics order=data;
class Species;
model SepalLength=Species;
lsmeans Species / stderr pdiff=all adjust=tukey;
run;quit;

proc sort data=sashelp.iris out=test2;
   by Species;
run;

proc glm data=test2 plots=diagnostics order=data;
class Species;
model SepalLength=Species;
lsmeans Species / stderr pdiff=all adjust=tukey;
run;quit;

Plot from first GLM:

 

 

desc.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Plot from second GLM:

 

 

asc.png

AnaVelloso
Calcite | Level 5

I am having troubles to sort the data with symbols.. I am pretty new using SAS, when is numbers or alphabetic order not problem but now I have symbols and numbers  <12,  >16 how I can short the data that comes in the order <12, 12, 13-15, 16, >16?

Thank you very much!

 

PeterClemmensen
Tourmaline | Level 20

There are several ways to do this, but here is a format approach to get the sort right:

 

data test;
input educ $;
datalines;
<12
12
13-15
<12
12
13-15
16 
>16?
16 
<12
12
13-15
16 
>16?
>16?
;

proc format;
   value $ fmt
      '<12'    = 1
      '12'     = 2
      '13-15'  = 3
      '16'     = 4
      '>16?'   = 5
   ;
run;

proc sql;
   create table sorted as 
   select * from test
   order by put(educ, $fmt.);
quit;

 

Result:

 

educ 
<12 
<12 
<12 
12 
12 
12 
13-15 
13-15 
13-15 
16 
16 
16 
>16? 
>16? 
>16? 

 

FreelanceReinh
Jade | Level 19

Hello @AnaVelloso,

 

Maybe it's even easier and you just need to specify order=internal in the PROC GLM statement. This would be sufficient if '<12' etc. were just formatted values of variable Educ, whose internal values (e.g., numeric values 1, 2, ...) reflected the desired sort order. (This is a common technique to avoid exactly these sorting issues.) Can you check in PROC CONTENTS output if Educ is numeric or character and whether a format is associated with it?

 

If, however, Educ is an unformatted character variable with values '<12' etc. you can create a view before the PROC GLM step and use this instead of another dataset:

proc sql;
create view _incomes as
select * from incomes
order by whichc(educ,'<12','12','13-15','16','>16');
quit;

ods graphics on;
proc glm data = _incomes plots=diagnostics order=data;
...

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 4 replies
  • 1730 views
  • 3 likes
  • 3 in conversation