Hello.
I have the following problem with sas list:
%let List =;
%let N_List = %sysfunc(countw(&List));
533 %let List =;
534 %let N_List = %sysfunc(countw(&List));
ERROR: The function COUNTW referenced by the %SYSFUNC or %QSYSFUNC macro function has too few
arguments
%if &list = %then %do;
..
%end;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
operand is required. The condition was: &list =
How to check if the list is empty???
Thank you very much for all your help
%if %superq(list) = %then %do;
...
%end;
Use a proper macro quoting function or make sure that the &list macro variable is available in the local symbol table for your macro (i.e. create it inside the macro def).
If you give %SYSFUNC() at least two arguments then it will not cause the COUNTW() function to issue that error.
937 %let List =;
938 %let N_List = %sysfunc(countw(&List,));
939 %put &=n_list;
N_LIST=0
But you really should be telling COUNTW() what delimiters to use. For example a space.
%let N_List = %sysfunc(countw(&List,%str( )));
Otherwise it uses multiple characters.
the default delimiters depend on whether your computer uses ASCII or EBCDIC characters.
If your computer uses ASCII characters, then the default delimiters are as follows:blank ! $ % & ( ) * + , - . / ; < ^ |In ASCII environments that do not contain the ^ character, the SCAN function uses the ~ character instead. If your computer uses EBCDIC characters, then the default delimiters are as follows:blank ! $ % & ( ) * + , - . / ; < ¬ | ¢
To simply test if the sting is empty I normally just test for non-zero length.
%if %length(&list) %then ...
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.