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

All,

 

I have a class variable: time_to_graduation

 

Time_to_graduation has the following possibilities:

'3-Year and Under Graduate'
'4-Year Graduate'
'5-Year Graduate'
'6-Year Graduate'
'7-Year Graduate'
'8-Year Graduate'
'9-Year Graduate'
'10-Year Graduate'

 

They are not tabulating in order I have listed. I numbered them intuitively hoping I wouldn't have to do any type of format step. Those hopes, however, were dashed when I tabulated the variable.  Let's just say, they are not in order.  I've attempted various fixes, but I can't seem to get it to work.

 

Any advice on getting the tabulation to display the time_to_graduate class variable to tabulate in the order i have above?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

As a character string, the values are alphabetized.  Since "1" alphabetizes before other digits, "10" will come out first.  A simple fix would be to add a blank before all the single-digit values:

 

' 3-Year and Under Graduate'

View solution in original post

6 REPLIES 6
Reeza
Super User

Replace them with codes, 1, 2, 3 etc in the correct order and then use a format to have the value displayed instead.

 


@eer_seer wrote:

All,

 

I have a class variable: time_to_graduation

 

Time_to_graduation has the following possibilities:

'3-Year and Under Graduate'
'4-Year Graduate'
'5-Year Graduate'
'6-Year Graduate'
'7-Year Graduate'
'8-Year Graduate'
'9-Year Graduate'
'10-Year Graduate'

 

They are not tabulating in order I have listed. I numbered them intuitively hoping I wouldn't have to do any type of format step. Those hopes, however, were dashed when I tabulated the variable.  Let's just say, they are not in order.  I've attempted various fixes, but I can't seem to get it to work.

 

Any advice on getting the tabulation to display the time_to_graduate class variable to tabulate in the order i have above?

 

Thanks!


 

eer_seer
Obsidian | Level 7

I follow on the first part of your suggestion, don't follow on the second.

Astounding
PROC Star

As a character string, the values are alphabetized.  Since "1" alphabetizes before other digits, "10" will come out first.  A simple fix would be to add a blank before all the single-digit values:

 

' 3-Year and Under Graduate'

eer_seer
Obsidian | Level 7

This was a great and simple solution to the problem and worked just as you described.  Thank you.

BrunoMueller
SAS Super FREQ

Check out the CLASSDATA= option it allows you to provide the data in a specific sequence. Additionally it provides a way to provide class values for which there is no data.

 

Here is an example:

data have;
  infile cards dsd;
  input 
    gradText : $30.
  ;
  seqNr + 1;
  random = rand("uniform");
  someValue = ceil( random * 100 );
cards;
'3-Year and Under Graduate'
'4-Year Graduate'
'5-Year Graduate'
'6-Year Graduate'
'7-Year Graduate'
'8-Year Graduate'
'9-Year Graduate'
'10-Year Graduate'
;

data classOrder;
  set have;
  keep gradtext;
run;

proc sort data=have out=have2;
  by random;
run;

proc tabulate data=have2 classdata=classorder;
  class gradText / order=data;
  var someValue;
  table 
    gradText, someValue
  ;
run;
eer_seer
Obsidian | Level 7

Ok, great!


This is helpful as well.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2171 views
  • 2 likes
  • 4 in conversation