DATA Step, Macro, Functions and more

Jumbling Observations

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

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
Super Contributor
Posts: 469

Re: Jumbling Observations

Posted in reply to thepushkarsingh

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

View solution in original post


All Replies
Super Contributor
Super Contributor
Posts: 260

Re: Jumbling Observations

Posted in reply to thepushkarsingh

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. 

Trusted Advisor
Posts: 1,288

Re: Jumbling Observations

Posted in reply to thepushkarsingh
  1. Make a new random variable. 
  2. Sort your data by that variable.
Super User
Posts: 22,850

Re: Jumbling Observations

Posted in reply to thepushkarsingh
Solution
‎02-28-2018 01:18 PM
Super Contributor
Posts: 469

Re: Jumbling Observations

Posted in reply to thepushkarsingh

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,541

Re: Jumbling Observations

Posted in reply to thepushkarsingh

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
Super Contributor
Posts: 260

Re: Jumbling Observations

Posted in reply to Astounding

But does she tell you you have an XY Problem?  Smiley Happy

Super User
Posts: 13,046

Re: Jumbling Observations


HB wrote:

But does she tell you you have an XY Problem?  Smiley Happy


Probably just the pesky XY chromosome pairing. Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 232 views
  • 6 likes
  • 7 in conversation