BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yichentian226
Obsidian | Level 7

Hi,

 

I have a column named journey. Under journey there're rows, eg: abc$def$fgu. Now I want to count how many "$" in each record. In this case there will be three.  Any help is appreciated! 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@yichentian226 wrote:

Hi,

 

I have a column named journey. Under journey there're rows, eg: abc$def$fgu. Now I want to count how many "$" in each record. In this case there will be three.  Any help is appreciated! 

 

 


The SAS Countc function counts number of occurrences of a character in a variable:

data example;
   journey="abc$def$fgu";
   dollarcount = countc(journey,"$");
run;

Your example only shows 2 $ signs. eg: abc$def$fgu. 

If you want to count the number of things SEPARATED by the $

data example2;
   journey="abc$def$fgu";
   dollarcount = countw(journey,"$");
run;

Countw counts "words". The second parameter would be a list of characters used to separate the pieces of the value. This just uses the $ sign to separate.

View solution in original post

2 REPLIES 2
ballardw
Super User

@yichentian226 wrote:

Hi,

 

I have a column named journey. Under journey there're rows, eg: abc$def$fgu. Now I want to count how many "$" in each record. In this case there will be three.  Any help is appreciated! 

 

 


The SAS Countc function counts number of occurrences of a character in a variable:

data example;
   journey="abc$def$fgu";
   dollarcount = countc(journey,"$");
run;

Your example only shows 2 $ signs. eg: abc$def$fgu. 

If you want to count the number of things SEPARATED by the $

data example2;
   journey="abc$def$fgu";
   dollarcount = countw(journey,"$");
run;

Countw counts "words". The second parameter would be a list of characters used to separate the pieces of the value. This just uses the $ sign to separate.

yichentian226
Obsidian | Level 7
THANKS SO MUCH! You rock!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 865 views
  • 0 likes
  • 2 in conversation