Reputation: 95
Suppose I have a list of variables with a common prefix. Is it possible to use If/then logic on all of those variables at once?
Data I have 3 columns:
data have;
length column1-column2 $8 column3 8;
input column1-column3;
datalines;
CC A_var1 12
HH A_var2 212
CC A_var3 221
CC B_var1 66
HH B_var2 545
CC B_var3 454
;
* untested;
data test;
set source;
if column1 = 'CC' then A: = .
run;
Upvotes: 1
Views: 563
Reputation: 51566
You can use the :
modifier on the operator in the IF statement to do a truncated string comparison.
data want;
set have;
if column1='CC' and column2 =: 'A_' then column3=.;
run;
Result
Obs column1 column2 column3
1 CC A_var1 .
2 HH A_var2 212
3 CC A_var3 .
4 CC B_var1 66
5 HH B_var2 545
6 CC B_var3 454
Upvotes: 1