BookmarkSubscribeRSS Feed
makset
Obsidian | Level 7

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

3 REPLIES 3
yabwon
Amethyst | Level 16
%if %superq(list) =  %then %do;
...
%end;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"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



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

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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1978 views
  • 0 likes
  • 4 in conversation