I am trying to check the length of a certain character variable. I have a variable id_Settings which all values should have a length of 8 e.g. CA455006. How do i use the length statement to check if all my observations in the ID_settings have the required length ?
Basically, how do I use length statement to check the length of variable ID_setting?
I have sample data but the original data has over 2 million encounters.
data check;
input Name $ 1-5 ID_setting $ 7-15;
datalines;
Dog DO123232
Cat CA345566
Mouse MO987973
Dog DO468579
Owl OW576864
Cat CA089854
run;
Thanks,
I think you don't mean the length of the character variable, I think you mean the length of the text string in each observation. These are not the same.
In that case, you use the LENGTH function.
data check;
input Name $ 1-5 ID_setting $ 7-15;
l=length(id_setting);
datalines;
Dog DO123232
Cat CA345566
Mouse MO987973
Dog DO468579
Owl OW576864
Cat CA089854
;
Actually, you might prefer function lengthn() since function length() will not let you know if you have empty strings.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.