Macros for SAS Application Developers
https://github.com/sasjs/core
mp_sortinplace.sas File Reference

Sorts a SAS dataset in place, preserving constraints. More...

Go to the source code of this file.

Detailed Description

Generally if a dataset contains indexes, then it is not necessary to sort it before performing operations such as merges / joins etc. That said, there are a few edge cases where it can be desirable:

  • To allow adjacent records to be viewed directly in the dataset
  • To apply compression, or to remove deleted records
  • To improve performance for specific queries

This macro will only work for BASE (V9) engine libraries. It works by creating a copy of the dataset (without data, WITH constraints) in the same library, appending a sorted view into it, and finally - renaming it.

Example usage:

proc sql;
create table work.example as
  select * from sashelp.class;
alter table work.example
  add constraint pk primary key(name);
%mp_sortinplace(work.example)
Parameters
[in]libdsThe libref.datasetname that needs to be sorted

SAS Macros

Related Macros

Version
9.2
Author
Allan Bowe

Definition in file mp_sortinplace.sas.