BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
harrylui
Obsidian | Level 7

good day

 

is there any function can count the blank from name string

 

FACEBK AABMSW FBMEADS IRL

 

like there are 3 blanks over the name string

 

 

 

i also do some data cleansing on this record and the result is FACEBKAAB

 

can i using that cleansing result and  scan/crosscheck the original record and show below result?

 

because i did the compress on my cleaned record and i wanted to keep that blank in this attempt of crosscheck

 

FACEBK AAB

 

so that i can know how well is my cleansing.

 

thanks in advance

Harry

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Character strings offer huge numbers of variations:  trailing blanks (that should presumably not be counted), multiple blanks between words (that presumably should be counted) to name a few.  I would try it differently:

 

data want;
   set have;
   n_blanks = lengthn(var) - lengthn(compress(var));
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20

data w;
str='FACEBK AABMSW FBMEADS IRL';
count=countc(str,' ');
run;

/*Or you could use S modifier in the same COUNTC function*/

data w;
str='FACEBK AABMSW FBMEADS IRL kjh';
count=countc(str,,'s');
run;

 

Reeza
Super User
Some other functions you may find useful, include COUNTC(), SCAN(), TRANSLATE() and COUNTW() which will count the number of words. You can use COUNTW() to find the number of words, and then loop with SCAN() to isolate each word if you want.
Astounding
PROC Star

Character strings offer huge numbers of variations:  trailing blanks (that should presumably not be counted), multiple blanks between words (that presumably should be counted) to name a few.  I would try it differently:

 

data want;
   set have;
   n_blanks = lengthn(var) - lengthn(compress(var));
run;
harrylui
Obsidian | Level 7

thank you all for helping

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1242 views
  • 4 likes
  • 4 in conversation