<?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 Passing macro variable in PROC SQL for ODBC data set in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721383#M27785</link>
    <description>&lt;P&gt;Hi&amp;nbsp; I would like to select macro value along with ODBC data set columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;connect&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; odbc(DSN=&amp;amp;DSN user=&amp;amp;user password=&amp;amp;pwds);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;create&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TABLEY&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; connection to odbc&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;y &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dates,* &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;TABLE X&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Feb 2021 20:14:54 GMT</pubDate>
    <dc:creator>Ashpak</dc:creator>
    <dc:date>2021-02-23T20:14:54Z</dc:date>
    <item>
      <title>Passing macro variable in PROC SQL for ODBC data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721383#M27785</link>
      <description>&lt;P&gt;Hi&amp;nbsp; I would like to select macro value along with ODBC data set columns&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;connect&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;to&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; odbc(DSN=&amp;amp;DSN user=&amp;amp;user password=&amp;amp;pwds);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;create&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; TABLEY&amp;nbsp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; * &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; connection to odbc&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;(&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;y &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; dates,* &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;TABLE X&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:14:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721383#M27785</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-02-23T20:14:54Z</dc:date>
    </item>
    <item>
      <title>Re: Passing macro variable in PROC SQL for ODBC data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721386#M27786</link>
      <description>What's in macro variable &amp;amp;Y?&lt;BR /&gt;&lt;BR /&gt;Essentially your code needs to resolve to valid SAS code so take whatever is in Y and literally put it into your code. If that doesn't run, it's not valid. &lt;BR /&gt;&lt;BR /&gt;select "ABC" as dates, * from table X that will work. &lt;BR /&gt;&lt;BR /&gt;Or &lt;BR /&gt;&lt;BR /&gt;select "01JAN2019"D as dates will also work. &lt;BR /&gt;&lt;BR /&gt;Select 2021-02-23 as DATES will probably work but not what you expect since 2021-2 = 2019 - 23 = 1998 as Dates&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721386#M27786</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-02-23T20:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Passing macro variable in PROC SQL for ODBC data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721391#M27787</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;x&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=today();&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;y=x;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;I am trying to get the date from date function and storing this variable into Y and calling this variable in ODBC select SQL&lt;/P&gt;&lt;P&gt;RROR: CLI describe error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name '&amp;amp;y'. : [Microsoft][SQL Server&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:40:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721391#M27787</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-02-23T20:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Passing macro variable in PROC SQL for ODBC data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721393#M27788</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/337616"&gt;@Ashpak&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;x&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=today();&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;y=x;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; y &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;I am trying to get the date from date function and storing this variable into Y and calling this variable in ODBC select SQL&lt;/P&gt;
&lt;P&gt;RROR: CLI describe error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Invalid column name '&amp;amp;y'. : [Microsoft][SQL Server&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That code it putting the same value into the dataset variables X and Y, but asking it display Y using the DATE format and letting X be displayed as just the raw number of days since 1960.&amp;nbsp; But since it is a DATA _NULL_ step both X and Y disappear when the step is over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to refence a macro variable named Y then you have to create a macro variable named Y.&amp;nbsp; If you want to use the value of the macro variable in the code you generate to run in your remote database then you need to know what type of value your remote database expects at that place in the code.&amp;nbsp; So if the macro variable Y is supposed to represent a date then you need know how that database expects you to represent a date.&amp;nbsp; You might try this syntax:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   call symputx('today',quote(put(today(),yymmdd10.),"'"));
run;
....
proc sql ;
connect to ... as X ... ;
create table want as 
  select * from connection to X 
  (select * from myschema.mytable where myvar = DATE &amp;amp;today)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Feb 2021 20:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Passing-macro-variable-in-PROC-SQL-for-ODBC-data-set/m-p/721393#M27788</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-02-23T20:49:31Z</dc:date>
    </item>
  </channel>
</rss>

