BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
n_alpha = length(compress(string, , 'ka'));
n_non_alpha = length(compress(string, , 'a'));

Probably need to test if that accounts for spaces correctly. 

 

Compress function is documented here

 

View solution in original post

2 REPLIES 2
Reeza
Super User
n_alpha = length(compress(string, , 'ka'));
n_non_alpha = length(compress(string, , 'a'));

Probably need to test if that accounts for spaces correctly. 

 

Compress function is documented here

 

Rick_SAS
SAS Super FREQ

Assuming that non-letters include spaces, punctuation, numbers, etc, you can use the ANYALPHA function to  differentiate letters from nonletters:

data Have;
length s $72;
input s 1-72;
/* number of letters and non-letters */
L = length(s);
nLetters = 0;
nNonLetters = 0;
do i = 1 to L;
isLetter = anyalpha(substr(s, i, 1));
nLetters + isLetter;
nNonLetters + ^isLetter;
end;
output;
drop i isLetter;
datalines;
In 28 days, the Anglo-Saxon lord ate 134 carrots. He had 20/20 vision!
e^{i*pi} + 1 = 0
ABCDEFG 123 HIJK 456 LMNOP 789 QRSTUV 0 WXYZ
;

proc print; run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 2 replies
  • 959 views
  • 1 like
  • 3 in conversation