Hi,
I defined a macrovariable:
%let InDomainWhere=>"30DEC2021"D;
and I need in a %if condition to count how many characters are present, how can I do that?
I was currently using
%if %eval(%sysfunc(count(%cmpress(&InDomainWhere.),%str( )))+0) = 0 %then %do;
but I realized that it only counts spaces and not all characters.
How can I do this?
Thanks
Luca
Count how many characters are present: use the %length() macro function.
%if %length(&indomainwhere)=0 %then %do;
or if necessary
%if %length(%cmpres(&indomainwhere)) %then %do;
but if &indomainwhere is a date, I don't see why you would need %cmpres
Count how many characters are present: use the %length() macro function.
%if %length(&indomainwhere)=0 %then %do;
or if necessary
%if %length(%cmpres(&indomainwhere)) %then %do;
but if &indomainwhere is a date, I don't see why you would need %cmpres
You can use the %LENGTH() function to count the number of BYTES, which in a single byte encoding is the same thing.
If the string in the macro variable could contain UTF-8 characters then you will need to use the KLENGTH() function to count the number of CHARACTERS.
994 %let InDomainWhere=>"30DEC2021"D; 995 %let bytes=%length(&indomainwhere); 996 %let chars=%sysfunc(klength(%superq(indomainwhere))); 997 %put &=bytes &=chars; BYTES=13 CHARS=13
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.