BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
songforu-8sdsa
Calcite | Level 5

 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. 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

10 REPLIES 10
mkeintz
PROC Star
  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.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
songforu-8sdsa
Calcite | Level 5

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

mkeintz
PROC Star

Then use the functions that Reeza identifies.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
songforu-8sdsa
Calcite | Level 5

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

 

Reeza
Super User

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 🙂

 

 

songforu-8sdsa
Calcite | Level 5

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.

Reeza
Super User

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. 

songforu-8sdsa
Calcite | Level 5

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

Reeza
Super User

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.

Reeza
Super User

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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