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. 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 1350 views
  • 0 likes
  • 4 in conversation