Scrambling a SAS Dataset

Accepted Solution Solved
Reply
Contributor
Posts: 40
Accepted Solution

Scrambling a SAS Dataset

Hi

I have a dataset with 10 variables and 600k records.  It is the end result of a number of preceding processes, and one of the effects of these processes is that the dataset is ordered by age.  Is there a simple sas procedure which can be written to get rid of the sorting ?  I don't want to do say 3 proc surveyselects and then put the datasets together again


Accepted Solutions
Solution
‎07-16-2015 03:53 AM
Respected Advisor
Posts: 3,065

Re: Scrambling a SAS Dataset

This will order your data randomly:

data want;

  set have;

  scramble_var = ranuni(0);

run;

proc sort data = want;

  by scramble_var;

run;

View solution in original post


All Replies
Solution
‎07-16-2015 03:53 AM
Respected Advisor
Posts: 3,065

Re: Scrambling a SAS Dataset

This will order your data randomly:

data want;

  set have;

  scramble_var = ranuni(0);

run;

proc sort data = want;

  by scramble_var;

run;

Contributor
Posts: 40

Re: Scrambling a SAS Dataset

Great thanks SASKiwi !

Esteemed Advisor
Esteemed Advisor
Posts: 7,249

Re: Scrambling a SAS Dataset

Hi,

Just for laughs, try proc whisk?

For the above, you could do in one step:

proc sql;

  create table want as select * from sashelp.cars order by ranuni(0);

quit;

Also, I would ask why do you want to scramble the dataset.  Generally ordered datasets would be easier to use, maybe you just need to change the order or retain original ordering:

data original;

     set original;

     ord=_n_;

run;

Then later on sort by _n_ to get it to the original sort.

Contributor
Posts: 40

Re: Scrambling a SAS Dataset

Also great thanks RW 9 !  I want to scramble the datasets so that the customers are not called in any predefined sequence or bias which is built in via the preceding datasteps

☑ This topic is SOLVED.

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

Discussion stats
  • 4 replies
  • 242 views
  • 3 likes
  • 3 in conversation