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
Onyx | Level 15
%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 ...

sas-innovate-2024.png

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
  • 831 views
  • 0 likes
  • 4 in conversation