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!

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

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