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. 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 7 replies
  • 1019 views
  • 6 likes
  • 7 in conversation