Hi SAS Users,
I wanted some help with getting the count of pipes '|' of a macro variable.
%LET DLM_COUNT = COUNTC(&PLATFORM,') +1;
&PLATFORM has value like 'ABC|DEF|GHI|QWE'
So i am expecting to 4 in DLM_COUNT.
Thanks,
Ana
Countc is a regulare sas function, not a macro function. So it has to be called via %sysfunc;
Also, you seem to want to count WORDs, where | is the separator:
%let PLATFORM =ABC|DEF|GHI|QWE;
%LET DLM_COUNT = %sysfunc(COUNTW(&PLATFORM,|));
%put &=dlm_count;
Countc is a regulare sas function, not a macro function. So it has to be called via %sysfunc;
Also, you seem to want to count WORDs, where | is the separator:
%let PLATFORM =ABC|DEF|GHI|QWE;
%LET DLM_COUNT = %sysfunc(COUNTW(&PLATFORM,|));
%put &=dlm_count;
Modifying your attempt slightly:
%let dlm_count = %sysfunc(countc(&platform, |));
I can't test it right now, but it looks like it should work.
In retrospect, COUNTW counts the number of words using pipes as delimiters. COUNTC counts number of pipes. Either is possible, just pick the one that does what you need.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.