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!
@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 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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.