Help using Base SAS procedures

deal with a bunch of variables ending with some common letter

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

deal with a bunch of variables ending with some common letter

Hi,

I need to drop a bunch of variables ending with either _xx or _xy. How to do it in SAS? the colon ":" seems only working for starting letters.

Thanks in advance.

Thanks,

Sunny


Accepted Solutions
Solution
‎01-07-2015 03:47 PM
Respected Advisor
Posts: 3,124

Re: deal with a bunch of variables ending with some common letter

data test;

     a=1;

     b=1;

     _xx=2;

     _xy=3;

run;

proc sql;

     select distinct name into :name separated by ' ' from dictionary.columns where libname='WORK' AND MEMNAME='TEST' AND prxmatch('/(_xx|_xy)$/io',TRIM(name))=0;

QUIT;

data want;

     set test (keep=&name);

run;

View solution in original post


All Replies
Super Contributor
Posts: 305

Re: deal with a bunch of variables ending with some common letter

hello,

something like this :

proc sql noprint;
select name into :vars separated by ' ' from sashelp.vcolumn
where memname='CLASS' and libname='SASHELP' AND name like '%e';
quit;

%put &vars;

data want;
set sashelp.class (drop=&vars) ;
run;

Contributor
Posts: 33

Re: deal with a bunch of variables ending with some common letter

Many thanks Loko!

Solution
‎01-07-2015 03:47 PM
Respected Advisor
Posts: 3,124

Re: deal with a bunch of variables ending with some common letter

data test;

     a=1;

     b=1;

     _xx=2;

     _xy=3;

run;

proc sql;

     select distinct name into :name separated by ' ' from dictionary.columns where libname='WORK' AND MEMNAME='TEST' AND prxmatch('/(_xx|_xy)$/io',TRIM(name))=0;

QUIT;

data want;

     set test (keep=&name);

run;

Contributor
Posts: 33

Re: deal with a bunch of variables ending with some common letter

Many thanks kuo!

Super User
Posts: 9,687

Re: deal with a bunch of variables ending with some common letter

Learn how to use escape character.

data test;

     a=1;

     b=1;

     _xx=2; xx=22;

     _xy=3; yy=33;

run;

proc sql;

     select distinct name into : name separated by ' '

      from dictionary.columns

         where libname='WORK' AND MEMNAME='TEST' AND

       (lowcase(name) like '%~_xx' escape '~'  or

        lowcase(name) like '%~_xy' escape '~'  );

QUIT;

data want;

     set test (drop=&name);

run;

Xia Keshan

☑ This topic is SOLVED.

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

Discussion stats
  • 5 replies
  • 259 views
  • 3 likes
  • 4 in conversation