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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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