-2

I have a hopefully simple SAS question.

I have created a data set DATA1 using PROC SQL; CREATE TABLE, etc. In order to create it I ordered some data set randomly and took the first 100 observations.

I now want to reorder the dataset. This seems like it should be easy, but the only way I've found to do it is to make a completely new data set and reorder it. How can I sort DATA1 itself?

Andrew Haynes
  • 2,612
  • 2
  • 20
  • 35
Lepidopterist
  • 391
  • 1
  • 5
  • 21
  • To make it so others can help you need to post sample data and examples of the code you tried including any error messages from the SAS log. – Tom Feb 11 '17 at 16:12
  • I posted an answer, but since there was no example data I had to make up the variable names to use the `BY` statement. – Tom Feb 11 '17 at 19:09
  • Thanks for the careful answer and your many comments. – Lepidopterist Feb 11 '17 at 19:32

1 Answers1

1

To sort a dataset in SAS you should use PROC SORT. If you do not specify an output dataset name then the default is to over write the source dataset.

proc sort data=data1;
  by var1 var2 ;
run;

Note that this will still require that the dataset be re-written, but SAS will handle the details for you behind the scenes.

Tom
  • 47,574
  • 2
  • 16
  • 29