Search notes:

SAS: proc datasets

proc datasets allows to modify a data set's attribute such as variable name, format/informat and label.
However, proc dataset cannot be used to change a variable's length or data type.

List SAS files in library

proc dataset can be used to show the data sets contained in a library
libname lib_one "p:\ath\to\a\directory";

/* Create three data sets in lib_one library: */
data lib_one.dataset_a;
  x = 'eggs';
run;

data lib_one.dataset_b;
  y = 'why';
run;

data lib_one.dataset_c;
  z = 'almost c';
run;

/* List files in library lib_one: */
proc datasets
     lib=lib_one;
run;
Github repository about-SAS, path: /programming/proc/datasets/list-files-in-lib/lib.sas
Alternatively, the members could also be determined by selecting from dictionary.members:
proc sql;
  select 
     memname,
     memtype
  from
     dictionary.members
  where
     libname = 'LIB_ONE';
quit;
Github repository about-SAS, path: /programming/proc/datasets/list-files-in-lib/dictionary.members.sas

Delete some data sets/files in a library

libname tq84_lib 'p:\ath\to\some\directory';

data tq84_lib.member_one  ; x=1; output; run;
data tq84_lib.member_two  ; x=2; output; run;
data tq84_lib.member_three; x=3; output; run;

proc sql;
  select memname
  from   dictionary.members
  where  libname = 'TQ84_LIB';
quit;

proc datasets
     library = tq84_lib;
     delete member_one member_three; /* remove some members/data sets from the library. */
run;

proc sql;
  select memname
  from   dictionary.members
  where  libname = 'TQ84_LIB';
quit;
Github repository about-SAS, path: /programming/proc/datasets/delete.sas

Copying members

%let dir_top = p:\ath\to\a\directory;

libname lib_src  "&dir_top\dir_src";
libname lib_dest "&dir_top\dir_dest";


/* Create three datasets in library */
data lib_src.dataset_a; x = 'eggs'    ; run;
data lib_src.dataset_b; y = 'why'     ; run;
data lib_src.dataset_c; z = 'almost c'; run;


proc datasets
          lib = lib_src ;
     copy out = lib_dest;
run;
Github repository about-SAS, path: /programming/proc/datasets/copy.sas

kill - Delete all data sets/files in a library

kill deletes all datasets/members within a library.
libname tq84_lib 'p:\ath\to\some\directory';

data tq84_lib.member_one  ; x=1; output; run;
data tq84_lib.member_two  ; x=2; output; run;
data tq84_lib.member_three; x=3; output; run;

proc sql;
  select memname
  from   dictionary.members
  where  libname = 'TQ84_LIB';
quit;

proc datasets 
     library=tq84_lib
     kill;/* Delete all files in the library at once */
run;

proc sql;
  select memname
  from   dictionary.members
  where  libname = 'TQ84_LIB';
quit;
Github repository about-SAS, path: /programming/proc/datasets/kill.sas

Create a unique index on a variable of a data set

libname tq84_ix 'p:\ath\to\some\directory';

proc datasets
     library=tq84_ix
     kill;
quit;


data tq84_ix.num;
  length num txt $ 10;
  input  num txt;
datalines;
1 one
2 two
3 three
4 four
5 five
6 six
7 seven
8 eight
9 nine
10 ten
run;

proc datasets
     library=tq84_ix;
     modify num;

  index create num / unique;
run;

proc sql;
  select
    name    , /* Column name: num    */
    idxusage, /* Index type : SIMPLE */
    indxname, /* Index name : num    */
    unique    /* Unique?    : yes    */
  from
    dictionary.indexes
  where
    libname = 'TQ84_IX' and
    memname = 'NUM';
quit;
Github repository about-SAS, path: /programming/proc/datasets/create-index/unique.sas

See also

proc contents
SAS programming: proc
data set

Index