DATA Step, Macro, Functions and more

how to count how many letters and vowels in character text file?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

how to count how many letters and vowels in character text file?

 and read a character at a time, using retain funcion, calculate the precetage of vowels in total letters, all in one proc print 

datalines;

A vendor was gathering data investigating why a router went down this past Monday evening -  causing a longer outage. While they were working another bug caused the router in question to reload. Since we had technicians on site, the outage was quickly resolved. 


Accepted Solutions
Solution
‎03-02-2017 06:58 PM
Super User
Posts: 19,851

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

Here's a start:

 

data have;
length random_statement $50.;
random_statement = "random text that doesn't matter";
string_no_spaces = compress(random_statement);
string_no_vowels = compress(string_no_spaces, 'aeiou', 'd');

length_full_statement = length(random_statement);
length_no_spaces = length(string_no_spaces); *note punctuation is still included - should it be?;
length_no_spaces_no_vowels = length(string_no_vowels);

run;

proc print data=have;
run;

View solution in original post


All Replies
Trusted Advisor
Posts: 1,022

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa
  1. RETAIN is a statement, not a function
  2. Must you use retain?If so, then please describe in words the sequence of steps you would perform if you were doing this manually.
Occasional Contributor
Posts: 6

Re: how to count how many letters and vowels in character text file?

not necessarily using retain, it's just a option. as long as I can know how many letters, vowels and ratio of those two in a character string.

Thank you

Trusted Advisor
Posts: 1,022

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

Then use the functions that Reeza identifies.

Occasional Contributor
Posts: 6

Re: how to count how many letters and vowels in character text file?

can you give me a exaple using the the string that listed?

Thanks

"A vendor was gathering data investigating why a router went down this past Monday evening -  

causing a longer outage.

While they were working another bug caused the router in question to reload.

Since we had technicians on site, the outage was quickly resolved. "

 

Super User
Posts: 19,851

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

Please clarify your questions. 

 

Functions that could help:

CHAR, LENGTH,  and COMPRESS

 

One quick trick may be to compress out all the spaces, count the number of characters via LENGTH, compress out the vowels and then count the LENGTH again. Then it's some basic math from there Smiley Happy

 

 

Occasional Contributor
Posts: 6

Re: how to count how many letters and vowels in character text file?

I just want to know how many letters and vowels in a character string and the precentage of vowels in total letters in details, how to code it

Thanks.

Super User
Posts: 19,851

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

I pretty much outlined the steps, is there something in particular that is unclear that you're having the issues. Applying functions to a string is a pretty straightforward task. 

Occasional Contributor
Posts: 6

Re: how to count how many letters and vowels in character text file?

I am just not sure how to show the output from a single PROC PRINT that outputs the final counts and percentages only.

Super User
Posts: 19,851

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

Include only those variables in your VAR statement in proc print or use a KEEP statement to only include those variables.

 

If you're doing text analytics are you using SAS Enterprise Miner? It should have point and click tools for this type of analysis.

Solution
‎03-02-2017 06:58 PM
Super User
Posts: 19,851

Re: how to count how many letters and vowels in character text file?

Posted in reply to songforu-8sdsa

Here's a start:

 

data have;
length random_statement $50.;
random_statement = "random text that doesn't matter";
string_no_spaces = compress(random_statement);
string_no_vowels = compress(string_no_spaces, 'aeiou', 'd');

length_full_statement = length(random_statement);
length_no_spaces = length(string_no_spaces); *note punctuation is still included - should it be?;
length_no_spaces_no_vowels = length(string_no_vowels);

run;

proc print data=have;
run;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 10 replies
  • 348 views
  • 0 likes
  • 3 in conversation