Hi! I'm trying to rename some observations in my school_name variable. Currently, the school names look like this:
I want to rename them to look like this:
In the data step, my code looks like this:
length school_name $ 30;
if school_name = "Washington Elem" then School_Name = "Washington Elementary School";
if school_name = "Lin coln School" then School_Name = "Lincoln Elementary School";
if school_name = "Adams Elem" then School_Name = "Adams Elementary School";
if school_name = "Jackson" then School_Name = "Jackson Elementary School";
However, after renaming, it looks like this:
Why do they get truncated? I added that line
length school_name $ 30;
in the hopes of the names not being truncated, but it didn't change anything.
try
length school_name $ 30;
before set statement
data have;
input school_name= $16. ;
school_name=dequote(school_name);
cards;
school_name = "Washington Elem"
school_name = "Lin coln School"
school_name = "Adams Elem"
school_name = "Jackson"
;
data want;
length school_name $ 30;
set have;
if school_name = "Washington Elem" then School_Name = "Washington Elementary School";
if school_name = "Lin coln School" then School_Name = "Lincoln Elementary School";
if school_name = "Adams Elem" then School_Name = "Adams Elementary School";
if school_name = "Jackson" then School_Name = "Jackson Elementary School";
run;
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.