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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.