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!

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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