Search code examples
sassas-macro

sas macro to delete all datasets from work lib clear all filename libname statements and delete user defined macro variables


i need a generic macro SAS to delete all data-sets from work lib clear all file-name libname statements and delete user defined macro variables.


Solution

  • You can try this:

    %macro clearALL;
    /*delete macro variables*/
    data delete;
    set sashelp.vmacro;
    where scope eq: 'G' and name ne: 'SYS';
    run;
    data _null_;
    set delete;
    call symdel(name);
    run;
    
    /*clear libnames and filenames*/
    libname _ALL_ clear;
    filename _ALL_ clear;
    /*deletes all datasets from work*/
    proc datasets lib=work kill noprint;
    run;
    %mend clearALL;