<?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: Calling a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165392#M31928</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, the macro will resolve correct:&lt;/P&gt;&lt;P&gt;%let firstday = put(intnx('month',today(),0),DATE9.);&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;&amp;nbsp; target=&amp;amp;firstday.;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the final code passed to compiler looks like:&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; target=put(intnx('month',today(),0),DATE9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would need to see the log warnings/errors, however, what is target as its not defined.&amp;nbsp; I also agree with DBailey, I don't see value in this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Aug 2014 13:32:59 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2014-08-18T13:32:59Z</dc:date>
    <item>
      <title>Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165389#M31925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data monthly_data&amp;nbsp; ;* add rows for months with no spend ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set summary1 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by id ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; priordate = lag( date ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.id then priordate= date ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; spend = . ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; target = date ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date = priordate ; &lt;SPAN style="color: #993300;"&gt;if last.id then target=&amp;amp;firstday. ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do while( intck( 'month', date, target) &amp;gt; 1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date= intnx( 'month', date, 1) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; keep id spend date ;&lt;/P&gt;&lt;P&gt;run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Allright if I insert the code marked in brown I try to make the last.id be equal to a macro which I have&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;firstday = put(intnx('month',today(),0),DATE9.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However this results in a syntax error....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 12:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165389#M31925</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2014-08-18T12:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165390#M31926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;"&amp;amp;firstday"d&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 12:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165390#M31926</guid>
      <dc:creator>Kiteulf</dc:creator>
      <dc:date>2014-08-18T12:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165391#M31927</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think the using "put(intnx('month',today(),0),DATE9.)"d will work either.&amp;nbsp; In this case, I think the SAS macro is just functioning as a text replacement and would put exactly what you typed into the data step.&amp;nbsp; I don't think using a macro gains you anything in this case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro firstday();&lt;/P&gt;&lt;P&gt;intnx('month',today(),0)&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 13:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165391#M31927</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-08-18T13:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165392#M31928</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Actually, the macro will resolve correct:&lt;/P&gt;&lt;P&gt;%let firstday = put(intnx('month',today(),0),DATE9.);&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;&amp;nbsp; target=&amp;amp;firstday.;&lt;BR /&gt;&amp;nbsp; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the final code passed to compiler looks like:&lt;/P&gt;&lt;P&gt;data a;&lt;/P&gt;&lt;P&gt;&amp;nbsp; target=put(intnx('month',today(),0),DATE9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Would need to see the log warnings/errors, however, what is target as its not defined.&amp;nbsp; I also agree with DBailey, I don't see value in this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 13:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165392#M31928</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-08-18T13:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165393#M31929</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So your question is more about referencing a macro variable than calling a macro.&lt;/P&gt;&lt;P&gt;If you create the macro variable before the data step using the code like this:&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%let&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; firstday = &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(intnx(month,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(today()),0),DATE9.);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then the value of the macro variable will look something like:&amp;nbsp; 01AUG2014 &lt;/P&gt;&lt;P&gt;Now if you try to type that into an assignment statement like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if last.id then target=01AUG2014 ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then SAS will not like that as you are neither assigning a number or a text string or even referencing another variable since variable names cannot start with digits.&amp;nbsp; So what you want to do is set TARGET to the DATE that is meant by that string.&amp;nbsp; So you want to use a date literal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if last.id then target="01AUG2014"d ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;And now the line in your program should be:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;if last.id then target="&amp;amp;firstday"d ;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 13:40:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165393#M31929</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-08-18T13:40:18Z</dc:date>
    </item>
    <item>
      <title>Re: Calling a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165394#M31930</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I meant to say that it would not resolve to a date.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Aug 2014 15:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calling-a-macro/m-p/165394#M31930</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-08-18T15:00:22Z</dc:date>
    </item>
  </channel>
</rss>

