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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 350 views
  • 1 like
  • 2 in conversation