<?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: Grabbing date from one table, converting to a macro, and using that date throughout other progra in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/853477#M337336</link>
    <description>Thank you Paige!</description>
    <pubDate>Thu, 12 Jan 2023 15:45:47 GMT</pubDate>
    <dc:creator>SASGeek</dc:creator>
    <dc:date>2023-01-12T15:45:47Z</dc:date>
    <item>
      <title>Grabbing date from one table, converting to a macro, and using that date throughout other programs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/850836#M336235</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm trying to grab a date from one table, convert it to a macro, and use it extract data from other tables. The issue is the date extracted (&amp;amp;asof) and using it in the 2nd sql. The table variable (proc_date) uses data in the format 2022-12-15. I've tried some other solutions but nothing seems to work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any and all suggestions are appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Paula&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; connect to odbc as odbc(dsn='mine');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table dates as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from connection to odbc&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(select date as asof&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from myperfectdatabase&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where month = 12);&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; disconnect from odbc;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select asof into :asofdt from dates;&lt;/P&gt;&lt;P&gt;quit;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;asofdt;&amp;nbsp; &amp;nbsp; /* date retrieved shows as 15dec2022 */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; connect to odbc as odbc(dsn='mine');&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;create table otherdata as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select * from connection to odbc&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(select var1, var2, var3&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from myotherperfectdatabase&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where proc_date =&lt;STRONG&gt;&amp;nbsp;&amp;amp;asofdt );&amp;nbsp; &amp;nbsp; /*&amp;lt;--- the issue is using the macro here. orig data in 2022-12-15 format */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; disconnect from odbc;&amp;nbsp;&lt;/P&gt;&lt;P&gt;quit;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 18:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/850836#M336235</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2022-12-22T18:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing date from one table, converting to a macro, and using that date throughout other progra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/850838#M336236</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;%put &amp;amp;asofdt;&amp;nbsp; &amp;nbsp; /* date retrieved shows as 15dec2022 */&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;SAS does not consider this a date. SAS considers it a text string with no particular meaning, even if humans assign a meaning to it. So you have to convert it to an actual SAS date value, which is the number of days since 01JAN1960.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let asofdt1=%sysfunc(inputn(&amp;amp;asofdt,date9.));
%put &amp;amp;=asofdt1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;So then, to use it in your second SQL, you want&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where proc_date = &amp;amp;asofdt1);&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;At this point, formats are irrelevant. SAS does all arithmetic and boolean operations on unformatted values, and so unformatted &amp;amp;asofdt1 works here.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Dec 2022 19:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/850838#M336236</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-12-22T19:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: Grabbing date from one table, converting to a macro, and using that date throughout other progra</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/853477#M337336</link>
      <description>Thank you Paige!</description>
      <pubDate>Thu, 12 Jan 2023 15:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grabbing-date-from-one-table-converting-to-a-macro-and-using/m-p/853477#M337336</guid>
      <dc:creator>SASGeek</dc:creator>
      <dc:date>2023-01-12T15:45:47Z</dc:date>
    </item>
  </channel>
</rss>

