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

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

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;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

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;
TPayne
Fluorite | Level 6
That worked- thank you so much
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
  • 2 replies
  • 856 views
  • 1 like
  • 2 in conversation