BookmarkSubscribeRSS Feed
Obsidian | Level 7

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


%if &list =  %then %do;

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

Onyx | Level 15
%if %superq(list) =  %then %do;
Polish SAS Users Group: and

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation

Tourmaline | Level 20

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).

Super User Tom
Super User

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;

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 ...


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 4 in conversation