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
Opal | Level 21

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
Opal | Level 21

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.

SAS INNOVATE 2024

Innovate_SAS_Blue.png

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. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 881 views
  • 2 likes
  • 4 in conversation