Help using Base SAS procedures

SAS Proc and sorting options

Accepted Solution Solved
Reply
Regular Contributor
Posts: 216
Accepted Solution

SAS Proc and sorting options

Hi

I am using Proc Sort to sort a data set with a specific variable which is a alpha variable. I know the two standard sort options are ascending and descending (and don't see any others), but is there another option for custom sorting by the values in a variable/column?

The values I am trying to sort are (ascend/desc do not order correctly):

0

1 to 5

6 - 12

13 to 17

18 +

Paul


Accepted Solutions
Solution
‎11-23-2012 10:16 AM
PROC Star
Posts: 7,471

Re: SAS Proc and sorting options

Paul, I think you are looking for:

data have;

  input column1 $ &;

  cards;

0

1 to 5

6 - 12

13 to 17

18 +

;

proc sort data=have SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON);

  by Column1;

run;

View solution in original post


All Replies
Solution
‎11-23-2012 10:16 AM
PROC Star
Posts: 7,471

Re: SAS Proc and sorting options

Paul, I think you are looking for:

data have;

  input column1 $ &;

  cards;

0

1 to 5

6 - 12

13 to 17

18 +

;

proc sort data=have SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON);

  by Column1;

run;

Regular Contributor
Posts: 216

Re: SAS Proc and sorting options

Thanks a lot again Art. That works fine.

Paul

Super User
Posts: 5,429

Re: SAS Proc and sorting options

If you always want to sort this column according to numeric value, I think it would be wise to concert the column to numeric.

Data never sleeps
Regular Contributor
Posts: 151

Re: SAS Proc and sorting options

makes a good point.  If you just store the raw numeric data, you can create and apply a format with the values in your post.  If you are summarising the data using any of the usual SAS procs, they will automatically group by the formatted values.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 217 views
  • 0 likes
  • 4 in conversation