O'Reilly logo

Combining and Modifying SAS® Data Sets: Examples Second Edition by Michele M. Burlew

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Example 9.16 Counting the Occurrences of a String

Goal

Count the number of occurrences of a set of character strings in the value of a character variable.

Example Features

Featured StepDATA step
Featured Step Options and StatementsCOUNT, COUNTC, and COUNTW functions

Input Data Set

Data set QUIZ_GRADES has quiz grades for four students. The grades are stored in one variable, QUIZ_STRING, and the grades are separated by commas.

          QUIZ_GRADES

Obs    student      quiz_string
 1       431       B+,B-,A,I,A+
 2       501       A,A,B,P,C,U,F
 3       289       A,A,B,A,A-,U
 4       130       C+,B-,I,?,W

Resulting Data Set

Output 9.16 QUIZ_SUMMARY Data Set

 Example 9.16 QUIZ_SUMMARY Obs student quiz_string n_quizzes super good fair bad no_grades invalid 1 431 B+,B-,A,I,A+ 5 1 3 0 0 1 0 2 501 A,A,B,P,C,U,F ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required