Removing variable names containing a specific string

I'm just starting to learn SAS and want to know if anyone knows about a way to remove certain variables from a dataset if they contain a specific word. I am working with a dataset that contains a huge number of variables (100+) with the word "Label" in them, and I want to delete them. Unfortunately, the word label is at the end of the variable name, so I cannot make a simple drop label :; Obviously, I could individually list all the variables, but I just wanted to find out if any of them knew an easier way to accomplish this task. Thanks for reading and for any help you can offer.

+4
source share
2 answers

Using the vcolumn and proc sql tables to create a macro variable macro:

proc sql noprint;

    select trim(compress(name))
    into :drop_vars separated by ' '
    from sashelp.vcolumn
    where libname = upcase('lib1')
        and
            memname = upcase('table1')
        and
            upcase(name) like '%LABEL%'
    ;
quit;

%put &drop_vars.;

data table2;
    set table1;
    drop  &drop_vars.;
run;

proc sql will create a list of all the variables from table1 in the library 'lib1', containing labelanywhere in the name, and place it in the macro variable drop_vars. (upper scale is used to reduce the likelihood of a problem)

The data step then uses the operator dropand variable drop_varsto remove all the variables in the list.

Note. Make sure you check the output %put statementto make sure you are not dropping the variables you want to keep

+3
source

- , , , , . ( ) :

  • dictionary.columns
  • sashelp.vcolumn
  • proc

- ( ), .

, , PROC SQL SELECT INTO :

proc sql;
select name into :droplist separated by ' '
 from dictionary.columns
 where libname='SASHELP' and memname='CLASS'
 and name like '%eigh%';
quit;

( eigh ,% - )

&droplist, drop.

data want;
set sashelp.class;
drop &droplist;
run;
+3

All Articles