DATA Step, Macro, Functions and more

Macro functon like COUNTW?

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

Macro functon like COUNTW?

I have a macro variable that is a list of variable names delimited by spaces. I want to make a new macro variable that is the count of the number of variable names in the macro list. I thought we had a macro function that would do this but I can’t seem to find it. Any general hints or a push in the right direction would be much appreciated.


Accepted Solutions
Solution
‎09-25-2014 06:08 PM
Super User
Super User
Posts: 6,499

Re: Macro functon like COUNTW?

With %SYSFUNC() almost any function is potentially a macro function now.

%let n=%sysfunc(countw(&list,%str( )));

View solution in original post


All Replies
Solution
‎09-25-2014 06:08 PM
Super User
Super User
Posts: 6,499

Re: Macro functon like COUNTW?

With %SYSFUNC() almost any function is potentially a macro function now.

%let n=%sysfunc(countw(&list,%str( )));

Occasional Contributor
Posts: 13

Re: Macro functon like COUNTW?

Thank you, Tom.

That worked like a charm!

Contributor
Posts: 50

Re: Macro functon like COUNTW?

Hi Tom,

%let n=%sysfunc(countw(&list,%str());

In this code,  what is the function of %str())?

Thanks !!!

Super User
Super User
Posts: 6,499

Re: Macro functon like COUNTW?

It tells the function which characters to consider as causing word boundaries. So %STR( ) tells to only consider a blank as the delimiter for work boundaries.

http://support.sas.com/documentation/cdl/en/lefunctionsref/67398/HTML/default/viewer.htm#p18xi2516ih...

If your computer uses ASCII characters, then the default delimiters are as follows:

blank ! $ % & ( ) * + , - . / ; < ^ |

Contributor
Posts: 50

Re: Macro functon like COUNTW?

Thanks, Tom.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 2700 views
  • 1 like
  • 3 in conversation