<?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 Multiple characters in a LET statement, then searching in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549636#M152533</link>
    <description>&lt;P&gt;I have a list of flags that I would like to define in a %LET statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%LET vcodes = LCI LJL DIB MEH CRB LEB BAS AGE STC DMA;&lt;/PRE&gt;&lt;P&gt;I then need to filter a couple of tables based on these, I've done this with a string of values, but it doesn't seem to work for characters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN (&amp;amp;vcodes);
RUN;&lt;/PRE&gt;&lt;P&gt;I have also tried:&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN ("&amp;amp;vcodes");
RUN;&lt;/PRE&gt;&lt;P&gt;With no luck, is there a trick to this? Why does it work for numeric values, but not character?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Tue, 09 Apr 2019 15:04:54 GMT</pubDate>
    <dc:creator>Seb_A_Sanders</dc:creator>
    <dc:date>2019-04-09T15:04:54Z</dc:date>
    <item>
      <title>Multiple characters in a LET statement, then searching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549636#M152533</link>
      <description>&lt;P&gt;I have a list of flags that I would like to define in a %LET statement&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%LET vcodes = LCI LJL DIB MEH CRB LEB BAS AGE STC DMA;&lt;/PRE&gt;&lt;P&gt;I then need to filter a couple of tables based on these, I've done this with a string of values, but it doesn't seem to work for characters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN (&amp;amp;vcodes);
RUN;&lt;/PRE&gt;&lt;P&gt;I have also tried:&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN ("&amp;amp;vcodes");
RUN;&lt;/PRE&gt;&lt;P&gt;With no luck, is there a trick to this? Why does it work for numeric values, but not character?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 15:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549636#M152533</guid>
      <dc:creator>Seb_A_Sanders</dc:creator>
      <dc:date>2019-04-09T15:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple characters in a LET statement, then searching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549641#M152536</link>
      <description>&lt;P&gt;You are missing the quotes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%LET vcodes = 'LCI' 'LJL' 'DIB';&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 15:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549641#M152536</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-09T15:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple characters in a LET statement, then searching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549642#M152537</link>
      <description>&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE  findw(symget('vcodes') , strip(warning_code) );
RUN;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 15:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549642#M152537</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-04-09T15:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple characters in a LET statement, then searching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549643#M152538</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79326"&gt;@Seb_A_Sanders&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;With no luck, is there a trick to this? Why does it work for numeric values, but not character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your code is not valid SAS syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For character values this resolves to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where warning_code in (LCI LJL DIB MEH CRB LEB BAS AGE STC DMA);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is not valid code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to add quotes around the values. There are a few ways to fix this, one is to manually add the quotes, another is to change how the macro variable is created so it adds the quotes and another is to modify the macro variable using functions to add the quotes after the fact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 15:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549643#M152538</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-04-09T15:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple characters in a LET statement, then searching</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549648#M152540</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/79326"&gt;@Seb_A_Sanders&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a list of flags that I would like to define in a %LET statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%LET vcodes = LCI LJL DIB MEH CRB LEB BAS AGE STC DMA;&lt;/PRE&gt;
&lt;P&gt;I then need to filter a couple of tables based on these, I've done this with a string of values, but it doesn't seem to work for characters:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN (&amp;amp;vcodes);
RUN;&lt;/PRE&gt;
&lt;P&gt;I have also tried:&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
   CREATE TABLE codes AS 
   SELECT 
*
      FROM Source_table
      WHERE warning_code IN ("&amp;amp;vcodes");
RUN;&lt;/PRE&gt;
&lt;P&gt;With no luck, is there a trick to this? Why does it work for numeric values, but not character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It does not work for character values because the result is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;WHERE warning_code IN ("LCI LJL DIB MEH CRB LEB BAS AGE STC DMA"); &lt;/PRE&gt;
&lt;P&gt;when what you would need is&lt;/P&gt;
&lt;PRE&gt;WHERE warning_code IN ("LCI" "LJL" "DIB" "MEH" "CRB" "LEB" "BAS" "AGE" "STC" "DMA"); 
&lt;/PRE&gt;
&lt;P&gt;Each literal value needs its own set of quotes. Numeric values, not needing quotes don't have this issue with macro substitution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one of many ways to create a quoted list of space delimited items.&lt;/P&gt;
&lt;PRE&gt;%macro quotevals(vcodes=);
%let temp=;
%do i= 1 %to %sysfunc(countw(&amp;amp;vcodes.));
   %let temp= &amp;amp;temp. %sysfunc(quote(%scan(&amp;amp;vcodes,&amp;amp;i)));
%end;
&amp;amp;temp
%mend;

%let qcodes = %quotevals(vcodes = LCI LJL DIB MEH CRB LEB BAS AGE STC DMA);
%put quoted codes=: &amp;amp;qcodes;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 15:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-characters-in-a-LET-statement-then-searching/m-p/549648#M152540</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-09T15:21:16Z</dc:date>
    </item>
  </channel>
</rss>

