Hello,
I have a dataset with over 1000 variables, I want to scan this entire dataset and create a subset of data that contains all variables with the suffix "_MEAN" Any insight would help. Thanks!
cat_mean cat_toy dog_mean dog_toy bird_mean bird_toy
7.00 2 0.987 56 1.345 67
What I want:
cat_mean dog_mean bird_mean
7.00 0.987 1.345
One way
data have;
input cat_mean cat_toy dog_mean dog_toy bird_mean bird_toy;
datalines;
7.00 2 0.987 56 1.345 67
;
proc sql noprint;
select name into :vars separated by ' '
from dictionary.columns
where upcase(libname)=upcase('work')
and upcase(memname)=upcase('have')
and upcase(name) like "%_MEAN";
quit;
data want;
set have;
keep &vars.;
run;
One way
data have;
input cat_mean cat_toy dog_mean dog_toy bird_mean bird_toy;
datalines;
7.00 2 0.987 56 1.345 67
;
proc sql noprint;
select name into :vars separated by ' '
from dictionary.columns
where upcase(libname)=upcase('work')
and upcase(memname)=upcase('have')
and upcase(name) like "%_MEAN";
quit;
data want;
set have;
keep &vars.;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.