Hi Guys
Here count function modifier 't' or 'T' doesn't trim trailing blanks where i was wrong please fix error
data count;
name="Tokyo Olympics 2020 ";
x=count(name,'a');
x1=count(name,'a','i');
x2=count(name,'2','T');
xlength=length(x);
x1ength=length(x1);
x2length=length(x2);
run;
COUNT returns a number; using LENGTH on a number will cause that number to be converted to character using the BEST. format (IIRC, BEST12.).
data count;
name="Tokyo Olympics 2020 ";
x=count(name,'a');
x1=count(name,'a','i');
x2=count(name,'a','T');
xlength=length(x);
x1ength=length(x1);
x2length=length(x2);
run;x2length result length is 12 even if I use letter 'a'
I will just repeat what @Kurt_Bremser already said:
@pavank wrote:
data count; name="Tokyo Olympics 2020 "; x=count(name,'a'); x1=count(name,'a','i'); x2=count(name,'a','T'); xlength=length(x); x1ength=length(x1); x2length=length(x2); run;x2length result length is 12 even if I use letter 'a'
That's because the BEST12. format results in a string with the number right-adjusted, and LENGTH counts all characters up to the last non-blank character, including all leading blanks.
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 save with the early bird rate—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.