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