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.
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.