Help using Base SAS procedures

How to delete all variables with the names as ???f

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

How to delete all variables with the names as ???f

Hello,

I have a dataset which has many variables. I don't need those variables which has 'f' in the last position of the name. For example, the names of those variables are like wagef, levelf, posf.

Thanks for help.


Accepted Solutions
Solution
‎01-06-2012 01:00 AM
Super User
Posts: 9,687

Re: How to delete all variables with the names as ???f

Combination of Patrick and LinLin.

proc sql noprint;

   select name into : names separated by ' '

   from dictionary.columns

   where libname='WORK' and memname='HAVE' and upcase(name) like '%F' ;

quit;

Ksharp

View solution in original post


All Replies
Super Contributor
Posts: 1,636

Re: How to delete all variables with the names as ???f

data have;

  input aaf bbbf ccc;

  cards;

  1 2 4

  2 3 8

  ;

proc sql noprint;

   select name into : names separated by ' '

   from dictionary.columns

   where libname='WORK' and memname='HAVE' and lowcase(substr(name,length(name),1))='f';

quit;

data want;

   set have (drop=&names);

  run;

  proc print;run;

                                          Obs    ccc

                                             1      4

                                             2      8

Linlin

Respected Advisor
Posts: 3,900

How to delete all variables with the names as ???f

data have;
   wagef=1;
   wage=1;
   wagefn=1;
   xageF=1;
run;

%let dellist=;
proc sql;
   select name into :dellist separated by ','
   from dictionary.columns
   where libname='WORK' and memname='HAVE' and upcase(name) like '%F'
   ;
   %macro _del;
      %if %bquote(&dellist) ne %bquote() %then
      %do;
         alter table work.have
            drop &dellist
         ;
      %end;
   %mend;
   %_del
quit;

proc contents data=work.have;
quit;

Solution
‎01-06-2012 01:00 AM
Super User
Posts: 9,687

Re: How to delete all variables with the names as ???f

Combination of Patrick and LinLin.

proc sql noprint;

   select name into : names separated by ' '

   from dictionary.columns

   where libname='WORK' and memname='HAVE' and upcase(name) like '%F' ;

quit;

Ksharp

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 155 views
  • 6 likes
  • 4 in conversation