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

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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

7 REPLIES 7
Shmuel
Garnet | Level 18

You may prefer use KEEP instead DROP.

Jackwangliang
Calcite | Level 5
Thank you
ChrisNZ
Tourmaline | Level 20

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;

 

novinosrin
Tourmaline | Level 20
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;
Jackwangliang
Calcite | Level 5
Thanks you.
Patrick
Opal | Level 21

@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; 
Jackwangliang
Calcite | Level 5
Thank you.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 7 replies
  • 637 views
  • 0 likes
  • 5 in conversation