I have an old and a new data set that looks like this
old data set
id group characteristics
1 age 2 years old
2 age 5 years old
new data set
id group characteristics
3 age 3 Years old
4 age 5 Years old
I want to combine these two. However, as you can see, the old data set has "years" and the new data set has "Years"
How can I change the characteristics in my new data set so they are all lower case? Is there a simple way other than writing the same line for every characteristic? e.g.,
if characteristics eq "3 Years old" then characteristics = "3 years old"
if characteristics eq "5 Years old" then characteristics = "5 years old"
Is there a simple way to do this all at once?
Thanks
data want;
set have;
characteristics = lowcase(characteristics);
run;
There are three basic character case functions in SAS: Lowcase, make all characters lower case, Upcase, make all characters upper case and Propcase, makes first letter of each "word" upper case and others lower case.
There are additional functions KLowcase, Kupcase and Kpropcase that do the same things for double-byte character sets.
data want;
set have;
new_var = lowcase(original_var);
run;
You can call it on your original variable, but it's probably a good idea to just create a new one.
data want;
set have;
characteristics = lowcase(characteristics);
run;
There are three basic character case functions in SAS: Lowcase, make all characters lower case, Upcase, make all characters upper case and Propcase, makes first letter of each "word" upper case and others lower case.
There are additional functions KLowcase, Kupcase and Kpropcase that do the same things for double-byte character sets.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.