BookmarkSubscribeRSS Feed
teja5959
Obsidian | Level 7

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)

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1285 views
  • 2 likes
  • 4 in conversation