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

Hello everyone, I have a question regarding proc sort. Anyone can help? Thanks in advance!

For example I have a dataset "survey", and a character variable "question" and want to sort it.

I hope to get the ideal sequence order, but I got the sorted sequence in the middle column. I wonder whether it is possible to get the ideal sequence in SAS? Thanks!!!

proc sort data=survey;

by question;

run;

original

sequence

after sorting

ideal

sequence

q2q1q1
q3q10q2
q4q2q3
q5q3q4
q1q4q5
q7q5q6
q10q6q7
q8q7q8
q9q8q9
q6q9q10
1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I think you are looking for the following:

data survey;

  input question $;

  cards;

q2

q3

q4

q5

q1

q7

q10

q8

q9

q6

;

proc sort data=survey SORTSEQ=linguistic

      (NUMERIC_COLLATION=ON);

  by question;

run;

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

I think you are looking for the following:

data survey;

  input question $;

  cards;

q2

q3

q4

q5

q1

q7

q10

q8

q9

q6

;

proc sort data=survey SORTSEQ=linguistic

      (NUMERIC_COLLATION=ON);

  by question;

run;

dart926
Calcite | Level 5

Hi Authur,

This is exactly what I wanted. Thank you so much!!!

Yanmin

Ksharp
Super User

Or a SQL way which has more power.

data survey;
  input question $;
  cards;
q2
q3
q4
q5
q1
q7
q10
q8
q9
q6
;
run;
proc sql;
 create table want as
  select * from survey order by input(compress(question, ,'kd'),best8.);
quit;

Ksharp

dart926
Calcite | Level 5

Thank you so much, Ksharp!

Your Sql code works very well. It is great to know both methods work.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 7324 views
  • 1 like
  • 3 in conversation