<?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: Is it possible to use a sas macro variable after connecting  to hadoop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/882068#M348505</link>
    <description>&lt;DIV class=""&gt;create table t1 as union all (select * from hvgrp."T_CDR_202212_1") union all (select * from hvgrp."T_CDR_202212_2") union all&lt;/DIV&gt;&lt;DIV class=""&gt;(select * from hvgrp."T_CDR_202212_10")&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;query variable from the code I have posted gives correct result. But my problem is ,it is not getting resloved inside hadoop execute&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;proc sql;&lt;BR /&gt;connect to hadoop as myconn(%connection_settings(HVGRP));&lt;BR /&gt;execute (&lt;BR /&gt;&amp;amp;query.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; /*This is&amp;nbsp; the place where query is not getting resolved since it is in hadoop I believe .I need a solution for&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this.Earlier to this ,query is getting resolved as expected in sas */&lt;/STRONG&gt;&lt;BR /&gt;) by myconn;&lt;BR /&gt;disconnect from myconn;&lt;BR /&gt;quit;&lt;/DIV&gt;</description>
    <pubDate>Fri, 23 Jun 2023 05:08:22 GMT</pubDate>
    <dc:creator>Sathya3</dc:creator>
    <dc:date>2023-06-23T05:08:22Z</dc:date>
    <item>
      <title>Is it possible to use a sas macro variable after connecting  to hadoop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/881880#M348455</link>
      <description>&lt;P&gt;Hi ,&lt;BR /&gt;I have to connect to hadoop from SAS using proc sql and combine HIVE tables using union all. I have to use HIVE QL&lt;BR /&gt;List of source tables are like t_cdr_202212_1,t_cdr_202212_2...so on till t_cdr_202212_n where n is not a fixed number and&amp;nbsp;it is a sequential number from 1 upwards&lt;BR /&gt;HVGRP is schema where hive tables are stored .%connection_settings is a macro to connect to hadoop from SAS&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;problem here is :&lt;/P&gt;&lt;P&gt;"&amp;amp;query. "macro variable is not getting resolved in below part of code as it is sas macro.Is there any way I can use a sas macro variable after connecting to hadoop. I have attached full code as well for your reference&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;connect to hadoop as myconn(%connection_settings(HVGRP));&lt;BR /&gt;execute (&lt;BR /&gt;&amp;amp;query.&lt;BR /&gt;) by myconn;&lt;BR /&gt;disconnect from myconn;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data t_cdr_202212_1;
input name $;
datalines;
aaa
bbB
CCC
;
run;

data t_cdr_202212_2;
input name $;
datalines;
aa
bb
;
run;

data t_cdr_202212_10;
input name $;
datalines;
aa
bb
;
run;


%macro test;
  /* Create table_list using DICTIONARY.TABLES */
  proc sql;
    create table table_list as
    select memname
    from dictionary.tables
    where libname = 'hvgrp'
      and memname like 'T_CDR_202212_%';
  quit;

  /* Sort the table_list in the proper order */
  data table_list_sorted;
    set table_list;
    num_part = input(substr(memname, length('T_CDR_202212_')+1), 8.);
  run;

  proc sort data=table_list_sorted;
    by num_part;
  run;

  /* Calculate the value of 'n' */
  proc sql noprint;
    select count(*) into :n
    from table_list_sorted;
  quit;

  /* Construct the query */
  %let query = %str(create table t1 as);

  %do i = 1 %to &amp;amp;n;
    data _null_;
      set table_list_sorted;
      if _n_ = &amp;amp;i then call symputx('table_name', memname);
    run;
    
    %let query = %str(&amp;amp;query. select * from hvgrp.&amp;amp;&amp;amp;table_name);

    %if &amp;amp;i &amp;lt; &amp;amp;n %then %let query = %str(&amp;amp;query. union all);
  %end;

  %put &amp;amp;query;

  proc sql;
    connect to hadoop as myconn(%connection_settings(HVGRP));
    execute (
      &amp;amp;query.
    ) by myconn;
    disconnect from myconn;
  quit;
%mend test;


%test;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2023 11:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/881880#M348455</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-06-22T11:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a sas macro variable after connecting  to hadoop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/881900#M348461</link>
      <description>&lt;P&gt;It should work fine, as long as the number of tables is small enough that the generated code fits in a single macro variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need the %STR() as there is NOTHING in the code you generating that needs to have macro quoting.&amp;nbsp; In fact the macro quoting might be the cause of the error. What did the macro variable end up containing?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You don't need (or want) the double &amp;amp; before the TABLE_NAME macro variable reference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might want to adds quotes around the table name, just in case it has something strange like embedded spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Construct the query */
  %let query=create table t1 as;
  %let sep;
  %do i = 1 %to &amp;amp;n;
    data _null_;
      set table_list_sorted (firstobs=&amp;amp;i obs=&amp;amp;i);
      call symputx('table_name', quote(strip(memname)));
    run;
    %let query = &amp;amp;query. &amp;amp;sep. (select * from hvgrp.&amp;amp;table_name);
    %let sep=union all;
  %end;
  %put &amp;amp;query;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2023 13:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/881900#M348461</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-06-22T13:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a sas macro variable after connecting  to hadoop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/882068#M348505</link>
      <description>&lt;DIV class=""&gt;create table t1 as union all (select * from hvgrp."T_CDR_202212_1") union all (select * from hvgrp."T_CDR_202212_2") union all&lt;/DIV&gt;&lt;DIV class=""&gt;(select * from hvgrp."T_CDR_202212_10")&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;query variable from the code I have posted gives correct result. But my problem is ,it is not getting resloved inside hadoop execute&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;proc sql;&lt;BR /&gt;connect to hadoop as myconn(%connection_settings(HVGRP));&lt;BR /&gt;execute (&lt;BR /&gt;&amp;amp;query.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; /*This is&amp;nbsp; the place where query is not getting resolved since it is in hadoop I believe .I need a solution for&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;this.Earlier to this ,query is getting resolved as expected in sas */&lt;/STRONG&gt;&lt;BR /&gt;) by myconn;&lt;BR /&gt;disconnect from myconn;&lt;BR /&gt;quit;&lt;/DIV&gt;</description>
      <pubDate>Fri, 23 Jun 2023 05:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/882068#M348505</guid>
      <dc:creator>Sathya3</dc:creator>
      <dc:date>2023-06-23T05:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use a sas macro variable after connecting  to hadoop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/882076#M348510</link>
      <description>&lt;P&gt;The macro variable resolves BEFORE the code gets sent to Hadoop.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Because you use %str() when populating the macro var there might be some invisible quotes that get in the way. I've seen this happening with Oracle.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try %unquote(&amp;amp;query).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2023 07:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Is-it-possible-to-use-a-sas-macro-variable-after-connecting-to/m-p/882076#M348510</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-06-23T07:04:24Z</dc:date>
    </item>
  </channel>
</rss>

