Hi,
From a table with many columns, how to select only the columns ending with the same word?
Thanks
ending with the same word or letter?
if word, the var name should be delimited with something like (_) I would think
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;
Thank you!
@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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.