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.
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;
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
Then use the functions that Reeza identifies.
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. "
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 🙂
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.
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.
I am just not sure how to show the output from a single PROC PRINT that outputs the final counts and percentages only.
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.