<?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: Hadoop Passthrough in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632299#M187452</link>
    <description>&lt;P&gt;From the Hive reference found &lt;A href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-CastingDates" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;TABLE class="confluenceTable tablesorter tablesorter-default" role="grid"&gt;
&lt;TBODY aria-live="polite" aria-relevant="all"&gt;
&lt;TR role="row"&gt;
&lt;TD class="confluenceTd"&gt;
&lt;P&gt;cast(string as date)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD class="confluenceTd"&gt;
&lt;P&gt;If the string is in the form 'YYYY-MM-DD', then a date value corresponding to that year/month/day is returned. If the string value does not match this formate, then NULL is returned.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or &lt;A href="https://bigdataprogrammers.com/string-date-conversion-hive/" target="_self"&gt;here&lt;/A&gt; a whole list of options if using to_date()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And now you can use your macro variables. You just need to enclose the values into single quotes when using in the Hive SQL. Here how that can be done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Today_SAS = %sysfunc(date(),Date9.);
%LET Run_Date = %SYSFUNC(INPUTN(&amp;amp;Today_SAS., Date9.));

/*This will give the date 3 months back */
%LET Three_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -3., B), Date9.);

/*Method 1:*/
%put Method 1: %unquote(%str(%'&amp;amp;Run_Date%'));
 
/*Method 2 (If running SAS 9.4 or greater):*/
%put Method 2: %tslit(&amp;amp;Run_Date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution above inspired by&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Concatenate-Single-Quote-with-text-of-a-Macro-Variable/td-p/8073" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your where clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where to_date(b.Element5) &amp;gt;= cast(%tslit(&amp;amp;Run_Date) as date)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Mar 2020 01:06:58 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-03-16T01:06:58Z</dc:date>
    <item>
      <title>Hadoop Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632298#M187451</link>
      <description>&lt;P&gt;So I understand how to set up automatic dates in SAS:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* Normal Date (today) */&lt;/P&gt;
&lt;P&gt;%let Today_SAS = %sysfunc(date(),Date9.);&lt;BR /&gt;%LET Run_Date = %SYSFUNC(INPUTN(&amp;amp;Today_SAS., Date9.));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/*This will give the date 3 months back */&lt;BR /&gt;%LET Three_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -3., B), Date9.);&lt;BR /&gt;/* This will give the date 6 months back */&lt;BR /&gt;%LET Six_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -6., B), Date9.);&lt;BR /&gt;/* This will give the date 9 months back */&lt;BR /&gt;%LET Nine_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -9., B), Date9.);&lt;BR /&gt;/* This will give the date 12 months back */&lt;BR /&gt;%LET Twelve_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -12., B), Date9.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My Question is how do I pass this macro into a Hadoop HIVE passthrough?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a crude example below of the code I am using to pass through to Hadoop.&amp;nbsp; I am hoping to automate the date process, but I am at a loss on this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL noerrorstop; 
  Connect to HADOOP (server='xxx' port=xxx); 
  Execute (set mapreduce.job.queuename=sas.xxx) by HADOOP; 
  Execute (set parquet.compression=SNAPPY) by HADOOP;
  Execute (drop table if exists test.test) by HADOOP; 
  Execute (create table test.test stored as parquet as

select distinct
a.Element1,
a.Element2,
a.Element3,
a.Element4,
b.Element5


from Test.Test2 as a

LEFT JOIN Test.Test3 b on
a.ElementJoin=b.ElementJoin

where to_date(b.Element5) &amp;gt;= ('2018-01-01')


  ) by hadoop;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for any suggestions or helpful material to reference.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 00:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632298#M187451</guid>
      <dc:creator>IgawaKei29</dc:creator>
      <dc:date>2020-03-16T00:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: Hadoop Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632299#M187452</link>
      <description>&lt;P&gt;From the Hive reference found &lt;A href="https://cwiki.apache.org/confluence/display/Hive/LanguageManual+Types#LanguageManualTypes-CastingDates" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;TABLE class="confluenceTable tablesorter tablesorter-default" role="grid"&gt;
&lt;TBODY aria-live="polite" aria-relevant="all"&gt;
&lt;TR role="row"&gt;
&lt;TD class="confluenceTd"&gt;
&lt;P&gt;cast(string as date)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD class="confluenceTd"&gt;
&lt;P&gt;If the string is in the form 'YYYY-MM-DD', then a date value corresponding to that year/month/day is returned. If the string value does not match this formate, then NULL is returned.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or &lt;A href="https://bigdataprogrammers.com/string-date-conversion-hive/" target="_self"&gt;here&lt;/A&gt; a whole list of options if using to_date()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And now you can use your macro variables. You just need to enclose the values into single quotes when using in the Hive SQL. Here how that can be done:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Today_SAS = %sysfunc(date(),Date9.);
%LET Run_Date = %SYSFUNC(INPUTN(&amp;amp;Today_SAS., Date9.));

/*This will give the date 3 months back */
%LET Three_SAS = %SYSFUNC(INTNX(MONTH, &amp;amp;Run_Date., -3., B), Date9.);

/*Method 1:*/
%put Method 1: %unquote(%str(%'&amp;amp;Run_Date%'));
 
/*Method 2 (If running SAS 9.4 or greater):*/
%put Method 2: %tslit(&amp;amp;Run_Date);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Solution above inspired by&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Concatenate-Single-Quote-with-text-of-a-Macro-Variable/td-p/8073" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your where clause:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where to_date(b.Element5) &amp;gt;= cast(%tslit(&amp;amp;Run_Date) as date)
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 01:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632299#M187452</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-16T01:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: Hadoop Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632301#M187454</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let today_hive = %sysfunc(date(),yymmddd10.);


where to_date(b.Element5) &amp;gt;= to_date(%nrbquote('&amp;amp;today_hive'))
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 01:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632301#M187454</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-16T01:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Hadoop Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632379#M187485</link>
      <description>&lt;P&gt;Thank you both!&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;both those solutions seem to work for what I need.&amp;nbsp; I wasn't sure if the passthru would accept SAS macro logic however I learned that the SAS system will first build the packet that it will be sending over to Hadoop/HIVE, which means that SAS will interpret the macro date first and make sure that my variable is added prior to it sending over the packet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I learned something from this.&amp;nbsp; Appreciate you both again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 10:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Hadoop-Passthrough/m-p/632379#M187485</guid>
      <dc:creator>IgawaKei29</dc:creator>
      <dc:date>2020-03-16T10:26:39Z</dc:date>
    </item>
  </channel>
</rss>

