BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sunny_Sun
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

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

5 REPLIES 5
Loko
Barite | Level 11

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;

Haikuo
Onyx | Level 15

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;

Ksharp
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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