J.Q
J.Q

Reputation: 1031

Remove variables by character pattern in variable name (SAS)

I'd like to drop all variables with a certain character segment in the name. Example below:

var1  var2   var3   o_var1   o_var2   o_var3
   1     1      1        3        2        5
   7     3      4        .       -1        5

I'd like to only keep those without the "o_" in front. I could sort positionally and keep the first x number of variables, but with 100s of variables with this pattern, I wanted to seek an alternative.

Upvotes: 0

Views: 596

Answers (1)

Longfish
Longfish

Reputation: 7602

Just use the colon wildcard operator.

data want;
set have (drop=o_:); /* drops all variables beginning with o_ */
run;

Upvotes: 3

Related Questions