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

I'm trying trying to sort: Week 2, Week 12, Week 16, Week 8, Week 4 in ascending order of week number, but could not get the order. Any suggestions please?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

It is not clear what type of variables you have.

 

Assuming the variable is character then you will get it sorted like:

'Week 12'
'Week 16'
'Week 2 '
'Week 4 '
'Week 8 '

in order to get it in order of the week number, you need keep the number as a separate numeric variable

to get it in order:  2 4 8 12 16.

 

 

View solution in original post

3 REPLIES 3
kiranv_
Rhodochrosite | Level 12

it is not very clear what you want to achieve. if you can show sample input data and result you want, someone will be able to help you

Shmuel
Garnet | Level 18

It is not clear what type of variables you have.

 

Assuming the variable is character then you will get it sorted like:

'Week 12'
'Week 16'
'Week 2 '
'Week 4 '
'Week 8 '

in order to get it in order of the week number, you need keep the number as a separate numeric variable

to get it in order:  2 4 8 12 16.

 

 

Reeza
Super User

You can create a new variable which is just the week number and use that’s to sort. 

You can also look into the collating sequence options within PROC sort. 

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

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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