The data used are literal character strings defined directly in the DATA steps via variable assignments.
1 Code Block
DATA STEP Data
Explanation : This DATA step block initializes a 'long' variable with a character string. The COUNTC function is then used to count all occurrences of the character 'a' (including duplicates) in the 'long' string. The result is stored in 'num_a' and displayed in the SAS log.
Copied!
data _null_ ;
long='a b c d a e d a e t g d a c s' ;
num_a=countc(long,'a') ;
put num_a= ;
run ;
1
DATA _null_ ;
2
long='a b c d a e d a e t g d a c s' ;
3
num_a=countc(long,'a') ;
4
put num_a= ;
5
RUN ;
2 Code Block
DATA STEP Data
Explanation : This DATA step block initializes a 'long' variable with another character string. The COUNT function is used to count occurrences of the 'dog' substring in the 'long' string. It is important to note that COUNT counts occurrences as distinct words by default, but the function can be more flexible depending on delimiters. Here, 'bigdog' will not be counted as an occurrence of 'dog' unless specific delimiters are used. The result is stored in 'num_dog' and displayed in the SAS log.
Copied!
data _null_ ;
long='dog cat rat bat dog camel dingo snake bigdog' ;
num_dog=count(long,'dog') ;
put num_dog= ;
run ;
1
DATA _null_ ;
2
long='dog cat rat bat dog camel dingo snake bigdog' ;
3
num_dog=count(long,'dog') ;
4
put num_dog= ;
5
RUN ;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.