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

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!

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

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

7 REPLIES 7
HB
Barite | Level 11 HB
Barite | Level 11

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. 

mkeintz
PROC Star
  1. Make a new random variable. 
  2. Sort your data by that variable.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
SuryaKiran
Meteorite | Level 14

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
Astounding
PROC Star

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.

HB
Barite | Level 11 HB
Barite | Level 11

But does she tell you you have an XY Problem?  🙂

ballardw
Super User

@HB wrote:

But does she tell you you have an XY Problem?  🙂


Probably just the pesky XY chromosome pairing. 🙂

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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