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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.