<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic help with using a string in a data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758318#M239424</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let name_list = 'DAN','CAROL','JUNE';
data _null_;
	/*	create name filters */
	length name_filter   $40;
	name_filter = " name in ("||&amp;amp;name_list.||   ")";
	call symputx('name_where',name_filter);
run;
%put name_where =====&amp;gt; &amp;amp;name_where.;
&lt;/LI-CODE&gt;
&lt;P&gt;This is the error I get.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable NAME_LIST resolves to 'DAN','CAROL','JUNE'&lt;BR /&gt;NOTE: Line generated by the macro variable "NAME_LIST".&lt;BR /&gt;29 'DAN','CAROL','JUNE'&lt;BR /&gt;_&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jul 2021 04:24:25 GMT</pubDate>
    <dc:creator>DanD999</dc:creator>
    <dc:date>2021-07-30T04:24:25Z</dc:date>
    <item>
      <title>help with using a string in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758318#M239424</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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?&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let name_list = 'DAN','CAROL','JUNE';
data _null_;
	/*	create name filters */
	length name_filter   $40;
	name_filter = " name in ("||&amp;amp;name_list.||   ")";
	call symputx('name_where',name_filter);
run;
%put name_where =====&amp;gt; &amp;amp;name_where.;
&lt;/LI-CODE&gt;
&lt;P&gt;This is the error I get.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SYMBOLGEN: Macro variable NAME_LIST resolves to 'DAN','CAROL','JUNE'&lt;BR /&gt;NOTE: Line generated by the macro variable "NAME_LIST".&lt;BR /&gt;29 'DAN','CAROL','JUNE'&lt;BR /&gt;_&lt;BR /&gt;388&lt;BR /&gt;200&lt;BR /&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;
&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 04:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758318#M239424</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-07-30T04:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: help with using a string in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758320#M239425</link>
      <description>&lt;P&gt;Try running the SAS code you generated without the macro variables. That will make the error message more understandable.&amp;nbsp; So replace the reference to NAME_LIST with its value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;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
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you stuck a comma into the middle of your assignment statement and SAS is not happy with syntax like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why use the data step at all?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let name_where=name in (&amp;amp;name_list) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;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.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	name_filter = cats("name in (","&amp;amp;name_list",")");
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are worried that NAME_LIST will contain double quotes already causing issue like:&lt;/P&gt;
&lt;PRE&gt;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.
&lt;/PRE&gt;
&lt;P&gt;then you could use the QUOTE() function, but then you need to macro quote the commas.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",%sysfunc(quote(%superq(name_list))),")");
	call symputx('name_where',name_filter);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or&amp;nbsp;you might want to just use SYMGET() instead of referencing the macro variable directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	length name_filter   $40;
	name_filter = cats("name in (",symget('name_list'),")");
	call symputx('name_where',name_filter);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 04:43:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758320#M239425</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-07-30T04:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: help with using a string in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758321#M239426</link>
      <description>&lt;P&gt;Why a data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;%let name_where = name in ( &amp;amp;name_list. );&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 04:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758321#M239426</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-07-30T04:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: help with using a string in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758326#M239431</link>
      <description>&lt;P&gt;Thanks for so many choices.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 05:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758326#M239431</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-07-30T05:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: help with using a string in a data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758328#M239433</link>
      <description>&lt;P&gt;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.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jul 2021 05:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-with-using-a-string-in-a-data-step/m-p/758328#M239433</guid>
      <dc:creator>DanD999</dc:creator>
      <dc:date>2021-07-30T05:31:06Z</dc:date>
    </item>
  </channel>
</rss>

