Drop lowercase variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Drop lowercase variable

Hi all,

 

How can I drop lowercase variable? For example,

 

original variable set:

 

CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE

 

target variable set:

 

CHF VALVVE PULMCIRC OBESE

 

Best,

 

JackLiang

 

 

 


Accepted Solutions
Solution
4 weeks ago
Respected Advisor
Posts: 4,466

Re: Drop lowercase variable

[ Edited ]
Posted in reply to Jackwangliang

@Jackwangliang

Or if the variables you want to drop always start with a lowercase o then here a coding variant to @novinosrin

data have;
  length CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 8;
  stop;
run;

proc sql noprint;
  select  name into :drop separated by ' '
    from dictionary.columns
    where libname='WORK' and memname='HAVE' and name like 'o%'
    ;
quit; 

data want;
  set have;
  drop &drop;
run;

 

Or this way in case your table is in a data base or/and you want to conserve indices and the like

data have;
  length CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 8;
  stop;
run;

%let drop=;
proc sql noprint feedback;
  select  name into :drop separated by ','
    from dictionary.columns
    where libname='WORK' and memname='HAVE' and name like 'o%'
    ;
  alter table have
    drop &drop
  ;
quit; 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,779

Re: Drop lowercase variable

Posted in reply to Jackwangliang

You may prefer use KEEP instead DROP.

Occasional Contributor
Posts: 17

Re: Drop lowercase variable

Thank you
PROC Star
Posts: 2,129

Re: Drop lowercase variable

[ Edited ]
Posted in reply to Jackwangliang

Like this?

data HAVE;
  retain CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 1;
run;
proc contents data=HAVE noprint out=CONT;
run;
data _null_;
  set CONT end=LASTOBS;
  if _N_ = 1                  then call execute('data WANT; set HAVE; drop ');
  if prxmatch('/[a-z]/',NAME) then call execute(NAME);
  if LASTOBS                  then call execute(';run;');
run;

 

PROC Star
Posts: 1,076

Re: Drop lowercase variable

Posted in reply to Jackwangliang
data have;
length CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 8;

run;
proc contents data=HAVE noprint out=_have;
quit;
proc sql;
select 	name into :drop separated by ' '
from _have 
where  anylower(name)>0;
QUIT;

data want;
set have;
drop &drop;
run;
Occasional Contributor
Posts: 17

Re: Drop lowercase variable

Posted in reply to novinosrin
Thanks you.
Solution
4 weeks ago
Respected Advisor
Posts: 4,466

Re: Drop lowercase variable

[ Edited ]
Posted in reply to Jackwangliang

@Jackwangliang

Or if the variables you want to drop always start with a lowercase o then here a coding variant to @novinosrin

data have;
  length CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 8;
  stop;
run;

proc sql noprint;
  select  name into :drop separated by ' '
    from dictionary.columns
    where libname='WORK' and memname='HAVE' and name like 'o%'
    ;
quit; 

data want;
  set have;
  drop &drop;
run;

 

Or this way in case your table is in a data base or/and you want to conserve indices and the like

data have;
  length CHF VALVVE PULMCIRC OBESE oCHF oVALVVE oPULMCIRC oOBESE 8;
  stop;
run;

%let drop=;
proc sql noprint feedback;
  select  name into :drop separated by ','
    from dictionary.columns
    where libname='WORK' and memname='HAVE' and name like 'o%'
    ;
  alter table have
    drop &drop
  ;
quit; 
Occasional Contributor
Posts: 17

Re: Drop lowercase variable

Thank you.
☑ This topic is solved.

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

Discussion stats
  • 7 replies
  • 160 views
  • 0 likes
  • 5 in conversation