BookmarkSubscribeRSS Feed
karine
Calcite | Level 5

Hi,

From a table with many columns, how to select only the columns ending with the same word?

Thanks 

5 REPLIES 5
novinosrin
Tourmaline | Level 20

ending with the same word or letter?

if word, the var name should be delimited with something like (_) I would think

karine
Calcite | Level 5
Hi
Some columns end with _b and others with _e. I want to keep those ending with _e.
Thanks
novinosrin
Tourmaline | Level 20
data have;
t_1e=.;
t_2e=.;
t_3e=.;
t_1b=.;
t_2b=.;
run;



proc sql;
select name into : var separated by ' '
from dictionary.columns
where libname='WORK' and memname='HAVE'
and  char(upcase(name),length(name))='E';
quit;

%put &var;

data want;
set have(keep=&var);
run;

 

karine
Calcite | Level 5

Thank you!

ballardw
Super User

@karine wrote:

Hi,

From a table with many columns, how to select only the columns ending with the same word?

Thanks 


Use this as a learning point for naming variables. If you know that you might have some requirement like this it would be better to originally name them as e_something. Then the task of using those names becomes three characters: e_: which would use all the variables that start with e_ .

 

Another consideration could be "what is the rest of the text of the name". If you have variables like House_e and House_b , Car_e and Car_b, a bunch of paired names. Perhaps your data would work better in a transposed form where you have a variable that takes on values of House and Car then two variable _e and _b.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 3430 views
  • 0 likes
  • 3 in conversation