BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ybz12003
Rhodochrosite | Level 12

Hello experts,

 

I would like to change the text into number format in several variables.  However, I found out the text format coming so many different ways.  For example, the positive answer is 'Yes', 'Y','y', 'YES', 'yes'.   My current coding couldn't cover all of the requirement.   Any idea how to fix it?  Thanks.

data want (drop =  A B C D E);
	 set have;
	 array Old (*) A B C D E;
	 array New (*) AA BB CC DD EE;
	 do i = 1 to dim(Old); 
	  if Old(i) in ('No', 'n') then New(i)=0;
	  else if Old(i) in ('Yes', 'y') then New(i)=1;
	  else if Old(i) in ('Unknown') then New(i)=9;
	end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data want (drop =  A B C D E);
	 set have;
	 array Old (*) A B C D E;
	 array New (*) AA BB CC DD EE;
	 do i = 1 to dim(Old); 
	  if upcase(Old(i)) in ('NO', 'N') then New(i)=0;
	  else if upcase(Old(i)) in ('YES', 'Y') then New(i)=1;
	  else if upcase(Old(i)) in ('UNKNOWN') then New(i)=9;
	end;
run;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
data want (drop =  A B C D E);
	 set have;
	 array Old (*) A B C D E;
	 array New (*) AA BB CC DD EE;
	 do i = 1 to dim(Old); 
	  if upcase(Old(i)) in ('NO', 'N') then New(i)=0;
	  else if upcase(Old(i)) in ('YES', 'Y') then New(i)=1;
	  else if upcase(Old(i)) in ('UNKNOWN') then New(i)=9;
	end;
run;
ybz12003
Rhodochrosite | Level 12

Thanks much!

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
  • 2 replies
  • 578 views
  • 2 likes
  • 2 in conversation