have data
data a;
input id white$ black$ Native$ American$ Asian $;
datalines;
101 1 . . . .
102 1 1 . . .
103 1 1 1 1 .
104 1 . . . .
105 . . . . 1
106 . . 1 1 .
107 . 1 . . .
108 . . 1 . .
109 . . . 1 .
run;
i want data this type of data how to do program ?
data aa;
length race $20;
input id white$ black$ Native$ American$ Asian $ race $;
datalines;
101 1 . . . . WHITE
102 1 1 . . . MULTIPUL
103 1 1 1 1 . MULTIPUL
104 1 . . . . WHITE
105 . . . . 1 ASIAN
106 . . 1 1 . MULTIPUL
107 . 1 . . . BLACK
108 . . 1 . . NATIVE
109 . . . 1 . AMERICAN
;
run;
Try this
data a;
input id white black Native American Asian;
datalines;
101 1 . . . .
102 1 1 . . .
103 1 1 1 1 .
104 1 . . . .
105 . . . . 1
106 . . 1 1 .
107 . 1 . . .
108 . . 1 . .
109 . . . 1 .
run;
data aa;
set a;
array arr {*} white--Asian;
if n(of arr[*]) > 1 then race='Multiple';
else race = vname(arr[whichn(1, of arr[*])]);
run;
Hi @teja5959
You can use an ARRAY to do this, and the VNAME() function to retrieve the column name when the value is 1:
data want;
set a;
length race $ 20;
array _race (*) white black Native American Asian;
do i=1 to dim(_race);
if sum(of _race(*)) = 1 then do;
if _race(i)=1 then race = upcase(vname(_race(i)));
end;
if sum(of _race(*)) > 1 then race = "MULTIPUL";
end;
drop i;
run;
Native and American as separate races????
Native what? Is this the Native Hawaiian/ Other Pacific Islander or Alaska Native/American Indian (two typical race categories in the US OMB playbook)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.