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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.