BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DanD999
Quartz | Level 8

 

 

I'm trying to create a filter to use in a proc sql. The comma in the string seems to be the issue. How do I get around the problem?

%let name_list = 'DAN','CAROL','JUNE';
data _null_;
	/*	create name filters */
	length name_filter   $40;
	name_filter = " name in ("||&name_list.||   ")";
	call symputx('name_where',name_filter);
run;
%put name_where =====> &name_where.;

This is the error I get.

 

SYMBOLGEN: Macro variable NAME_LIST resolves to 'DAN','CAROL','JUNE'
NOTE: Line generated by the macro variable "NAME_LIST".
29 'DAN','CAROL','JUNE'
_
388
200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Try running the SAS code you generated without the macro variables. That will make the error message more understandable.  So replace the reference to NAME_LIST with its value.

1236  data _null_;
1237    length name_filter   $40;
1238    name_filter = " name in ("||'DAN','CAROL','JUNE'||   ")";
                                         -
                                         388
                                         200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

1239    call symputx('name_where',name_filter);
1240  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1238:31   1238:45
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      1:1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

So you stuck a comma into the middle of your assignment statement and SAS is not happy with syntax like that.

 

Why use the data step at all?

%let name_where=name in (&name_list) ;

Of if you do want to use the data step code then make sure you are generating valid SAS code. While you are at it use one of the new CATxxx functions instead of the concatenation operator.

	name_filter = cats("name in (","&name_list",")");

If you are worried that NAME_LIST will contain double quotes already causing issue like:

1246    name_filter = cats("name in (",""DAN","CAROL","JUNE"",")");
                                          --        ---
                                          1         49
                                            ---
                                            49
                                               -----
                                               388
                                               -----
                                               76
WARNING 1-322: Assuming the symbol AND was misspelled as AN.

NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space
             between a quoted string and the succeeding identifier is recommended.

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

then you could use the QUOTE() function, but then you need to macro quote the commas.

data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",%sysfunc(quote(%superq(name_list))),")");
	call symputx('name_where',name_filter);
run;

Or you might want to just use SYMGET() instead of referencing the macro variable directly.

data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",symget('name_list'),")");
	call symputx('name_where',name_filter);
run;

 

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Try running the SAS code you generated without the macro variables. That will make the error message more understandable.  So replace the reference to NAME_LIST with its value.

1236  data _null_;
1237    length name_filter   $40;
1238    name_filter = " name in ("||'DAN','CAROL','JUNE'||   ")";
                                         -
                                         388
                                         200
ERROR 388-185: Expecting an arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

1239    call symputx('name_where',name_filter);
1240  run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      1238:31   1238:45
NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      1:1
NOTE: The SAS System stopped processing this step because of errors.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds

So you stuck a comma into the middle of your assignment statement and SAS is not happy with syntax like that.

 

Why use the data step at all?

%let name_where=name in (&name_list) ;

Of if you do want to use the data step code then make sure you are generating valid SAS code. While you are at it use one of the new CATxxx functions instead of the concatenation operator.

	name_filter = cats("name in (","&name_list",")");

If you are worried that NAME_LIST will contain double quotes already causing issue like:

1246    name_filter = cats("name in (",""DAN","CAROL","JUNE"",")");
                                          --        ---
                                          1         49
                                            ---
                                            49
                                               -----
                                               388
                                               -----
                                               76
WARNING 1-322: Assuming the symbol AND was misspelled as AN.

NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.  Inserting white space
             between a quoted string and the succeeding identifier is recommended.

ERROR 388-185: Expecting an arithmetic operator.

ERROR 76-322: Syntax error, statement will be ignored.

then you could use the QUOTE() function, but then you need to macro quote the commas.

data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",%sysfunc(quote(%superq(name_list))),")");
	call symputx('name_where',name_filter);
run;

Or you might want to just use SYMGET() instead of referencing the macro variable directly.

data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",symget('name_list'),")");
	call symputx('name_where',name_filter);
run;

 

DanD999
Quartz | Level 8

Thanks for so many choices.

ChrisNZ
Tourmaline | Level 20

Why a data step?

 

%let name_where = name in ( &name_list. );

 

 

DanD999
Quartz | Level 8

I had code already where I built several filters using a data step. I didn't think of the simplest way to do it. I need the data step because there are other decisions that have to be made depending on other data passed in to the report. Thanks for the reply.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

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