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;
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;
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;
Thanks much!
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.
Ready to level-up your skills? Choose your own adventure.