Another way to examine multiple variables for the same value is the WHICHC function for Character values or WHICHN for Numeric values.
Note here is also a way to provide an example data set:
data example;
input (asian black pacific white other) ($);
datalines;
x . . . .
. x . . .
. . x . .
. . . x .
. . . . x
. . . . .
;
data want;
set example;
race = whichc('x',asian, black, pacific, white, other);
if race = 0 then race=.;
run;
Whichc, or Whichn, return the position position number of the value if found or 0 otherwise. Since your problem is related to the sequence of position this function does most of the work.
Great big caveat: Nothing in your code provides for multiple race codes selected and a very large number of data systems that collect race will allow multiple answers. If that is possible in your data you likely need to address that potential issue. Quite possibly with a bit more work depending on values and any other rules for your use.
You can test for that with code like:
Proc freq data=demo;
tables asian* black* pacific* white* other/ list missing;
run;
If any of the output lines have more than one variable with an X you need to address that.
... View more