<?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 Define local SQL-variable using explicit pass-through in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465419#M14475</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is it possible (and how) to define a local SQL variable using ODBC-explicit-pass-through? I mean something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
  Connect To ODBC (DSN=&amp;lt;Source&amp;gt;);
  Create Table xx As 
  Select *
  From Connection To ODBC
  (
  Declare @Max_KeyDate

  Select @Max_KeyDate = Max(KeyDate) From &amp;lt;view&amp;gt;

  Select * From &amp;lt;view&amp;gt; Where Key_Date = @Max_KeyDate
  );
  Disconnect from ODBC;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx &amp;amp; kind regards&lt;/P&gt;</description>
    <pubDate>Mon, 28 May 2018 08:05:32 GMT</pubDate>
    <dc:creator>user24feb</dc:creator>
    <dc:date>2018-05-28T08:05:32Z</dc:date>
    <item>
      <title>Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465419#M14475</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is it possible (and how) to define a local SQL variable using ODBC-explicit-pass-through? I mean something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
  Connect To ODBC (DSN=&amp;lt;Source&amp;gt;);
  Create Table xx As 
  Select *
  From Connection To ODBC
  (
  Declare @Max_KeyDate

  Select @Max_KeyDate = Max(KeyDate) From &amp;lt;view&amp;gt;

  Select * From &amp;lt;view&amp;gt; Where Key_Date = @Max_KeyDate
  );
  Disconnect from ODBC;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thx &amp;amp; kind regards&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 08:05:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465419#M14475</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2018-05-28T08:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465424#M14476</link>
      <description>&lt;P&gt;Store in a macro variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc SQL;
  Connect To ODBC (DSN=&amp;lt;Source&amp;gt;);
  Create Table xx As 
  Select max_key_date into :max_key_date
  From Connection To ODBC
  (
  Select Max(KeyDate) as max_key_date From &amp;lt;view&amp;gt;
  );
  Disconnect from ODBC;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;After that, use &amp;amp;max_key_date where needed. Be aware that you might have to do a conversion so the SAS macro variable holds the correct numerical value for dates and datetimes, as the different RDBMS systems have different ways of storing, handling and displaying such values.&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 08:41:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465424#M14476</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-28T08:41:50Z</dc:date>
    </item>
    <item>
      <title>Re: Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465427#M14477</link>
      <description>&lt;P&gt;Yes, a macro var is an alternative, but in this case leads to an %unquote(%str( ..)). I only would like to know, if it's possible and what's the effort.&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 08:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465427#M14477</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2018-05-28T08:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465429#M14478</link>
      <description>&lt;P&gt;A macro var is not an alternative, it is the only solution. SAS does not have SQL variables (and the declare statement) that you are used to. In SAS you use macro variables.&lt;/P&gt;
&lt;P&gt;Format the date in the remote SQL to something you can easily use in SAS (eg, first convert to a YYYY-MM-DD string, and then take the max() of that). After that, do a quick conversion to a SAS date value:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let max_key_date=2018-05-28; /* this is what you should get from the remote SQL call */

%let max_key_date=%sysfunc(inputn(&amp;amp;max_key_date,yymmdd10.));

%put &amp;amp;max_key_date;

data _null_;
td = today();
put td=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;the data step is in there to show you that the conversion in the %sysfunc works.&lt;/P&gt;</description>
      <pubDate>Mon, 28 May 2018 08:58:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465429#M14478</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-28T08:58:57Z</dc:date>
    </item>
    <item>
      <title>Re: Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465514#M14483</link>
      <description>&lt;P&gt;Did you try running those three remote statements separately?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;connect ... ;
execute (Declare @Max_KeyDate) by ODBC;
execute (Select @Max_KeyDate = Max(KeyDate) From &amp;lt;view&amp;gt;) by ODBC;
create table xx as 
  select *
  from connection to ODBC
  ( 
  Select * From &amp;lt;view&amp;gt; Where Key_Date = @Max_KeyDate
  );
disconnect ...;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 May 2018 17:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465514#M14483</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-28T17:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Define local SQL-variable using explicit pass-through</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465608#M14492</link>
      <description>&lt;P&gt;When I combine execute (declare @MaxDate select @MaxDate&amp;nbsp;= ..) it seems to work, at least I am not getting an error message. However, the local variable seems to be erased between the statements, so&amp;nbsp;I cannot use it in the create-table-from-connection-statement. It seems it is something I just should not do.&lt;/P&gt;</description>
      <pubDate>Tue, 29 May 2018 06:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Define-local-SQL-variable-using-explicit-pass-through/m-p/465608#M14492</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2018-05-29T06:39:54Z</dc:date>
    </item>
  </channel>
</rss>

