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
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.