## Jumbling Observations

Solved
Occasional Contributor
Posts: 7

# Jumbling Observations

I need to jumble my observations. Like if I have following:

1

2

3

4

5

6

.

Then I need any jumbled list like:

5

3

6

1

4

2

.

Any easy idea?

Any code to randomize the order in which observations are in data will be of great help.

Thanks a lot!

Accepted Solutions
Solution
‎02-28-2018 01:18 PM
PROC Star
Posts: 629

## Re: Jumbling Observations

Check the RAND() function if you have SAS9.4M4 or Later

``````DATA TEST;
input num;
random_num=RAND("NORMAL");
datalines;
1
2
3
4
5
;
run;

PROC SORT DATA=Test;
by random_num;
run;``````
Thanks,
Suryakiran

All Replies
Super Contributor
Posts: 269

## Re: Jumbling Observations

This smacks of an XY Problem.  Perhaps you could tell us what you are trying to do in a larger context?

In the immediate:  You could generate a random number for each observation and then sort by the random number.

Posts: 1,389

## Re: Jumbling Observations

1. Make a new random variable.
2. Sort your data by that variable.
Super User
Posts: 23,998

## Re: Jumbling Observations

Solution
‎02-28-2018 01:18 PM
PROC Star
Posts: 629

## Re: Jumbling Observations

Check the RAND() function if you have SAS9.4M4 or Later

``````DATA TEST;
input num;
random_num=RAND("NORMAL");
datalines;
1
2
3
4
5
;
run;

PROC SORT DATA=Test;
by random_num;
run;``````
Thanks,
Suryakiran
Super User
Posts: 6,931

## Re: Jumbling Observations

You should just look at me, and do whatever I do.  My observations are always jumbled.  At least that's what my wife tells me.

Super Contributor
Posts: 269

## Re: Jumbling Observations

But does she tell you you have an XY Problem?

Super User
Posts: 13,926

## Re: Jumbling Observations

HB wrote:

But does she tell you you have an XY Problem?

Probably just the pesky XY chromosome pairing.

☑ This topic is solved.