<?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: Have a statement evaluated and the value be used as a macro parameter using %Let in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330365#M74095</link>
    <description>&lt;P&gt;Sorry - my correction, or something else?&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2017 00:15:09 GMT</pubDate>
    <dc:creator>LaurieF</dc:creator>
    <dc:date>2017-02-07T00:15:09Z</dc:date>
    <item>
      <title>Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330333#M74073</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have what I believe is a relatively simple task.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a program where a date variable is used as a macro parameter...something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%program(data_file, date_start)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to add a let statement within the program which will essentially add days to the date variable to increase the amount of data that is processed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'd like it to look something like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%program(data_file, date_start,numberofdays)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And it will process a data step that looks something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let Date_end = &amp;amp;Date + &amp;amp;numberofdays;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;import&lt;/STRONG&gt; datafile="Datafile"&lt;/P&gt;&lt;P&gt;dbms=xlsx&lt;/P&gt;&lt;P&gt;out=work.Data;&lt;/P&gt;&lt;P&gt;sheet= "sheet1";&lt;/P&gt;&lt;P&gt;where Datetime &amp;gt;=&lt;STRONG&gt;"&amp;amp;Date_start:6:00"DT&lt;/STRONG&gt; and Datetime &amp;lt;= &lt;STRONG&gt;"&amp;amp;Date_end:5:59"DT&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I make the %let statement evaluate &amp;amp;Date + &amp;amp;numberofdays????&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 22:09:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330333#M74073</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2017-02-06T22:09:59Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330338#M74078</link>
      <description>&lt;P&gt;For a start, you'll have to convert the date into "number of days since 1 Jan 1960".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are a myriad of ways of doing this. What I'd recommend woud be to do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = 15Oct1983;
%let numberofdays = 15;

%let date_end = %sysevalf("&amp;amp;date"d + &amp;amp;numberofdays);

%put %sysfunc(putn(&amp;amp;date_end, date9.));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro function&amp;nbsp;&lt;EM&gt;%sysevalf&lt;/EM&gt;, although it is primarily used for floating point evaluations, has a nice side-effect of allowing interpretation of external date values.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 22:18:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330338#M74078</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-06T22:18:12Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330356#M74088</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It seems to want to work, but it appears to be having a problem converting the numeric into a date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: CLI prepare error: [Microsoft][ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to datetime.&lt;BR /&gt;SQL statement: execute InsightGetGoogleAnalytcisInfo "23JAN2017","20851".&lt;BR /&gt;NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 23:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330356#M74088</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2017-02-06T23:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330358#M74090</link>
      <description>&lt;P&gt;I'm not sure you can do a WHERE filter on PROC IMPORT the way you're invisioning.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your initial code showed importing from an Excel file and the current error indicates a database access so there's a disconnect happening somewhere here.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 23:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330358#M74090</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-02-06T23:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330359#M74091</link>
      <description>&lt;P&gt;I didn't know you could put a&amp;nbsp;&lt;EM&gt;where&lt;/EM&gt; clause in&amp;nbsp;&lt;EM&gt;proc import&lt;/EM&gt;. Cool! So the date value needs to be converted back into an external representation again. Sorry about that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date = 15Oct1983;
%let numberofdays = 15;

%let date_end = %sysfunc(putn(%sysevalf("&amp;amp;date"d + &amp;amp;numberofdays), date9.));

%put &amp;amp;date_end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Feb 2017 23:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330359#M74091</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-06T23:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330361#M74093</link>
      <description>&lt;P&gt;It worked! It was not an issue with the where statement or it being a proc import or database. Just the formating. Thanks!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Feb 2017 23:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330361#M74093</guid>
      <dc:creator>SmcGarrett</dc:creator>
      <dc:date>2017-02-06T23:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330365#M74095</link>
      <description>&lt;P&gt;Sorry - my correction, or something else?&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 00:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330365#M74095</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-07T00:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Have a statement evaluated and the value be used as a macro parameter using %Let</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330366#M74096</link>
      <description>&lt;P&gt;The clue was &lt;SPAN&gt;&lt;EM&gt;SQL statement: execute InsightGetGoogleAnalytcisInfo "23JAN2017","20851"&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;20851 is clearly a SAS date value, but the first parameter is a date I'd expect ODBC (or whatever the engine is) to accept.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2017 00:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Have-a-statement-evaluated-and-the-value-be-used-as-a-macro/m-p/330366#M74096</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-07T00:47:33Z</dc:date>
    </item>
  </channel>
</rss>

