BookmarkSubscribeRSS Feed
pavank
Quartz | Level 8

Hi Guys,

Good Evening

How to get sorted  datasets and notsorted datasets  list  in a library

2 REPLIES 2
Kathryn_SAS
SAS Employee

I am not sure if this is what you are asking, but in the output data set from PROC CONTENTS there is a SORTED variable. It will have a value of 1 if the data set is sorted or missing (.) if it is not. Here is a simple example.

proc sort data=sashelp.class out=class;
by age;
run;

proc sort data=sashelp.cars out=cars;
by type;
run;

data test;
x=1;
run;

proc contents data=work._all_ noprint out=allds(keep=libname memname sorted);
run;

data allds;
set allds;
by libname memname;
if first.memname then output;
run;

proc print data=allds;
run;
Quentin
Super User

Looks like you can pull this from dictionary.tables:

 

proc sql ;
  select memname, sortname, sorttype, sortchar
  from dictionary.tables 
  where libname="WORK" 
  ;
quit ;

See also this thread, which uses dictionary.columns : 
https://communities.sas.com/t5/SAS-Programming/Keeping-the-defined-sortedby-values-in-the-metadata/t...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 2 replies
  • 1513 views
  • 6 likes
  • 3 in conversation