BookmarkSubscribeRSS Feed
teja5959
Fluorite | Level 6

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;

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
ed_sas_member
Meteorite | Level 14

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;
ballardw
Super User

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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 877 views
  • 2 likes
  • 4 in conversation