turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Sort a column by variable

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 12, 2017 6:36 AM
(262 views)

Hi,

How would I go about creating a new column that contains the sorted values of one column by another variabe?

An example to hopefully clarify: if I had a table with two rows: Name and age, how would I create a third row that displays the names sorted from oldest to youngest?

Thanks!

3 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 12, 2017 10:12 AM
(252 views)

What you've asked for is not easily done in a formula (that I can come up with anyway). It's relatively easy to do this interactively by using **Tables->Sort** to sort the table into a new table and then copy and paste the column of interest back into the original table.

However the question raises some interest about what you're really trying to do.

Generally speaking, a row of a data table represents a collection of values for a single entity – an individual student in your simple example – and each row is unrelated to other rows. I'm not sure how this new column – of Names in your example – would be useful in an analysis since the new column is only meaningful in the context of it's order.

Can you explain a little bit more of how you'd use this new column?

An example to hopefully clarify: if I had a table with two rows: Name and age, how would I create a third row that displays the names sorted from oldest to youngest?

PS: you seem to have confused rows and columns in your example. I'm assuming that you really meant *a table with two columns* and that you wanted to create a third column as your original question states. If I'm mistaken and you really meant rows, please let us know.

-Jeff

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 14, 2017 11:48 PM
(221 views)

Hello,

If the column names share the same prefix, followed by consecutive numbers, an easier way to sort them is to use a SAS variable list. In a previous example, the columns are named day001, day002, day003, …, day365. They can be represented by the syntax day001-day365. Using a SAS variable list in the RETAIN statement will effectively put the columns in sorted order.

data fix3; retain salesman day001-day365; set output; run;

Hope it helps you, Thanks.

Madison Quinn

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jun 15, 2017 12:50 AM
(211 views)

Madison,

You seem to have added a SAS/Basic response to the SAS JMP Discussion group.

Jim