<?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 Re: How to use a macro in a proc sql statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-in-a-proc-sql-statement/m-p/240510#M44384</link>
    <description>Macro variable is text replacement, so your macro variables are replaced where you indicate which resolves to:&lt;BR /&gt;&lt;BR /&gt;11568  %PUT &amp;amp;startmonth &amp;amp;endmonth;&lt;BR /&gt;"201506" "201508"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Which translates to&lt;BR /&gt;"&amp;amp;startmonth" &amp;lt;= YearMonth &amp;lt;= "&amp;amp;endmonth"&lt;BR /&gt;""201506"" &amp;lt;= YearMonth &amp;lt;= ""201508""&lt;BR /&gt;&lt;BR /&gt;Issues with this:&lt;BR /&gt;1. too many quotation marks&lt;BR /&gt;2. Types don't match char vs num.&lt;BR /&gt;&lt;BR /&gt;Fix:&lt;BR /&gt;1. Remove quotes from macro variable&lt;BR /&gt;2. Remove quotes from And condition&lt;BR /&gt;&lt;BR /&gt;%LET date = %SYSFUNC(today());&lt;BR /&gt;%LET startmonth = %SYSFUNC(intnx(month,&amp;amp;date,-6),yymmn6.);&lt;BR /&gt;%LET endmonth = %SYSFUNC(intnx(month,&amp;amp;date,-4),yymmn6.);&lt;BR /&gt;%PUT &amp;amp;startmonth &amp;amp;endmonth;&lt;BR /&gt;&lt;BR /&gt;AND &amp;amp;startmonth &amp;lt;= YearMonth &amp;lt;= &amp;amp;endmonth</description>
    <pubDate>Tue, 22 Dec 2015 18:06:59 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2015-12-22T18:06:59Z</dc:date>
    <item>
      <title>How to use a macro in a proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-in-a-proc-sql-statement/m-p/240504#M44381</link>
      <description>&lt;P&gt;I created this macro:&lt;/P&gt;&lt;P&gt;%LET date = %SYSFUNC(today());&lt;BR /&gt;%LET startmonth = %STR(%")%SYSFUNC(intnx(month,&amp;amp;date,-6),yymmn6.)%STR(%");&lt;BR /&gt;%LET endmonth = %STR(%")%SYSFUNC(intnx(month,&amp;amp;date,-4),yymmn6.)%STR(%");&lt;BR /&gt;%PUT &amp;amp;startmonth &amp;amp;endmonth;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to the variable YearMonth to fall in between my startmonth and endmonth macros. Using the below statement gives me the error: Expression using IN has components that are of different data types. &amp;nbsp;YearMonth is (float,null).&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE Policy AS&lt;BR /&gt;SELECT&lt;BR /&gt;A.Policy,&lt;BR /&gt;A.PlanCode,&lt;BR /&gt;A.I_EmpID,&lt;BR /&gt;A.YearMonth&lt;BR /&gt;FROM&lt;BR /&gt;TestData A&lt;BR /&gt;WHERE&lt;BR /&gt;A.System = 'NPS'&lt;BR /&gt;AND DistributionChannel = 'Direct'&lt;BR /&gt;AND "&amp;amp;startmonth" &amp;lt;= YearMonth &amp;lt;= "&amp;amp;endmonth"&lt;BR /&gt;;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Dec 2015 17:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-in-a-proc-sql-statement/m-p/240504#M44381</guid>
      <dc:creator>Roddy</dc:creator>
      <dc:date>2015-12-22T17:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to use a macro in a proc sql statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-in-a-proc-sql-statement/m-p/240510#M44384</link>
      <description>Macro variable is text replacement, so your macro variables are replaced where you indicate which resolves to:&lt;BR /&gt;&lt;BR /&gt;11568  %PUT &amp;amp;startmonth &amp;amp;endmonth;&lt;BR /&gt;"201506" "201508"&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Which translates to&lt;BR /&gt;"&amp;amp;startmonth" &amp;lt;= YearMonth &amp;lt;= "&amp;amp;endmonth"&lt;BR /&gt;""201506"" &amp;lt;= YearMonth &amp;lt;= ""201508""&lt;BR /&gt;&lt;BR /&gt;Issues with this:&lt;BR /&gt;1. too many quotation marks&lt;BR /&gt;2. Types don't match char vs num.&lt;BR /&gt;&lt;BR /&gt;Fix:&lt;BR /&gt;1. Remove quotes from macro variable&lt;BR /&gt;2. Remove quotes from And condition&lt;BR /&gt;&lt;BR /&gt;%LET date = %SYSFUNC(today());&lt;BR /&gt;%LET startmonth = %SYSFUNC(intnx(month,&amp;amp;date,-6),yymmn6.);&lt;BR /&gt;%LET endmonth = %SYSFUNC(intnx(month,&amp;amp;date,-4),yymmn6.);&lt;BR /&gt;%PUT &amp;amp;startmonth &amp;amp;endmonth;&lt;BR /&gt;&lt;BR /&gt;AND &amp;amp;startmonth &amp;lt;= YearMonth &amp;lt;= &amp;amp;endmonth</description>
      <pubDate>Tue, 22 Dec 2015 18:06:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-a-macro-in-a-proc-sql-statement/m-p/240510#M44384</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2015-12-22T18:06:59Z</dc:date>
    </item>
  </channel>
</rss>

