BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8


Can you sort a field in a dataset without affecting the order of other fields. Or can you sort multiple fields of a data set independently from each other?

4 REPLIES 4
Haikuo
Onyx | Level 15

You can't, but you can cheat. But Why?

proc sort data=sashelp.class out=temp(keep=age);

     by age;

run;

data want;

     set sashelp.class;

     set temp;

run;

'class' was sorted by 'name', now the 'age' is also sorted . 

SASKiwi
PROC Star

Sorting usually describes changing the order of data rows.

If I understand your questions correctly, they are about changing the order columns/fields within a table - please confirm. If you want to change the order of a field where would you want to place it? First? Last? The 10th field?

An example of what you want would be useful.

Astounding
PROC Star

Sorting in SAS usually refers to changing the order of the rows.  The entire row moves as a unit.  However ...

If you are interested in changing the values of some of the fields within a single row, you can do that without affecting other fields within the same row:

data want;

set have;

call sortn (hand1, hand2, flop1, flop2, flop3, river, turn);

run;

Use SORTN if  your variables are numeric, or use SORTC if your variables are character.

brophymj
Quartz | Level 8

Thank you

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
  • 1834 views
  • 1 like
  • 4 in conversation