<?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 PROC SQL and MACROS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329388#M73683</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a macro variable with value as %let Alert=2017-01,2017-02,2017-03;&lt;/P&gt;
&lt;P&gt;I need to resolve this macro value in proc sql code.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;select * from Alerts where alert in("&amp;amp;Alert");&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for using this macro i need to put single quotes to the value of a macro and also the macro value is dynamic and it depends upon number of records in a column (Alert).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many Thanks In Advance For Your Reply&lt;/P&gt;</description>
    <pubDate>Thu, 02 Feb 2017 11:49:06 GMT</pubDate>
    <dc:creator>sandeep_reddy</dc:creator>
    <dc:date>2017-02-02T11:49:06Z</dc:date>
    <item>
      <title>PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329388#M73683</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a macro variable with value as %let Alert=2017-01,2017-02,2017-03;&lt;/P&gt;
&lt;P&gt;I need to resolve this macro value in proc sql code.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;Proc sql;&lt;/P&gt;
&lt;P&gt;select * from Alerts where alert in("&amp;amp;Alert");&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for using this macro i need to put single quotes to the value of a macro and also the macro value is dynamic and it depends upon number of records in a column (Alert).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many Thanks In Advance For Your Reply&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 11:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329388#M73683</guid>
      <dc:creator>sandeep_reddy</dc:creator>
      <dc:date>2017-02-02T11:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329390#M73684</link>
      <description>&lt;P&gt;What do you mean the macro variable is dynamic and how do the number of records matter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why the need for single quotes, are you using SQL Pass Thru?&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 12:01:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329390#M73684</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-02T12:01:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329392#M73685</link>
      <description>&lt;P&gt;Personally I rarely use macro variables for "data". &amp;nbsp;I would put your "data" in datasets, then use the data as you would any other data. &amp;nbsp;Macro has limitations, and coding with it is verbose and messy. &amp;nbsp;So:&lt;/P&gt;
&lt;PRE&gt;%let Alert=2017-01,2017-02,2017-03;
/* this bit just converts the macro variable to a dataset */
data vals;
  do i=1 to countw("&amp;amp;alert.",",");
    item=scan("&amp;amp;alert.",i,",");
    output;
  end;
run;

proc sql;
  select  * 
  from    ALERTS 
  where   ALERT in(select ITEM from VALS);
quit;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 12:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329392#M73685</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-02T12:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329393#M73686</link>
      <description>&lt;P&gt;Actually, what you are saying is that the macro variable was built incorrectly. &amp;nbsp;When it was built, there should have been quotes around each item in the list. &amp;nbsp;One alternative is to fix it now. &amp;nbsp;Another is to go back to the process that creates it and fix it there. &amp;nbsp;There are other alternatives, as other posters have noted.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 12:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329393#M73686</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-02T12:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329406#M73687</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let Alert=2017-01,2017-02,2017-03;

%Let Alert_Where=%BQuote(%Str(%')%Sysfunc(TranWrd(%BQuote(&amp;amp;Alert.),%Str(,),%Str(%', %')))%Str(%'));
%Put ***&amp;amp;Alert_Where.***;

* .. but don't do this, if it comes from a data set then use Proc SQL;
Data Dates;
  D='2017-01'; Output;
  D='2017-02'; Output;
  D='2017-03'; Output;
Run;
Proc SQL NoPrint;
  Select Catt("'",D,"'") Into :Alert_Where_SQL Separated By ',' From Dates;
Quit;
%Put ***&amp;amp;Alert_Where_SQL.***;

* .. else define Alert the way you need it in the first place;
%Let Alert_Comma='2017-01', '2017-02' ,'2017-03' ;
%Put ***&amp;amp;Alert_Comma.***;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Feb 2017 13:13:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329406#M73687</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2017-02-02T13:13:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL and MACROS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329422#M73698</link>
      <description>&lt;P&gt;Use QUOTE function to add quotes, instead of CATT&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Select quote(d, "'") into :alert_list separated by ", "&lt;/P&gt;
&lt;P&gt;from ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2017 14:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-and-MACROS/m-p/329422#M73698</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-02T14:11:08Z</dc:date>
    </item>
  </channel>
</rss>

