<?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: A simple macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218643#M40285</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Yes. Sort your data on report id and descending report date. Use a data step with BY report date. Use retain (with firs. logic) or lag() to compare report date between observations. Keep records that meets your criteria.&lt;/P&gt;&lt;P&gt;2. No.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 25 May 2015 10:45:24 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2015-05-25T10:45:24Z</dc:date>
    <item>
      <title>A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218642#M40284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would describe my knowledge and abilities in programing and macros as basic. This is my problem:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a dataset. I will refer to it as "history". In history, each observation is a summary of a report, including a date of issue and various variables. Reports are issued at different times, i.e. the difference in months between a report and a previous report could be any value between 1 and 24.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to create a new dataset. In this dataset the first observation would be the most recent report in history. The second observation would be the next and closest report in history, conditional on the fact it was issued at least 6 months later than the report in the FIRST observation. The third observation would now be the next report in history, conditional on the fact it was issued at least 6 months later than the report in the SECOND observation, and so forth. In other words, I have a reference date that needs to be updated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Can this be done without a macro? How?&lt;/P&gt;&lt;P&gt;2. Must this be done with a macro? How?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Michael&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 09:55:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218642#M40284</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-25T09:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218643#M40285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;1. Yes. Sort your data on report id and descending report date. Use a data step with BY report date. Use retain (with firs. logic) or lag() to compare report date between observations. Keep records that meets your criteria.&lt;/P&gt;&lt;P&gt;2. No.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 10:45:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218643#M40285</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-05-25T10:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218644#M40286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since the first observation is the most &lt;SPAN style="text-decoration: underline;"&gt;recent&lt;/SPAN&gt; report, by definition there can be no &lt;SPAN style="text-decoration: underline;"&gt;later&lt;/SPAN&gt; report. So I guess you meant "earlier"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 25 May 2015 16:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218644#M40286</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-05-25T16:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218645#M40287</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you. I'll try that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 02:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218645#M40287</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-26T02:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218646#M40288</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, sorry. Earlier of course.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 02:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218646#M40288</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-26T02:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218647#M40289</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry, this solution is not working;&lt;/P&gt;&lt;P&gt;I used:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data aborthist;&lt;/P&gt;&lt;P&gt;set aborthist;&lt;/P&gt;&lt;P&gt;by descending startdate;&lt;/P&gt;&lt;P&gt;if _n_=1 OR (lag(startdate)-startdate ge 180) then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apparently, the lag function queues the value of the previous observation. However, the previous observation is not necessarily the observation I need for the reference date. The reference date is the date belonging to the previous observation THAT WAS KEPT. For example, I have the&amp;nbsp; dates:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May 2014&lt;/P&gt;&lt;P&gt;Dec 2013&lt;/P&gt;&lt;P&gt;Jun 2013&lt;/P&gt;&lt;P&gt;Mar 2013&lt;/P&gt;&lt;P&gt;Jan 2013&lt;/P&gt;&lt;P&gt;Aug 2012&lt;/P&gt;&lt;P&gt;Mar 2012&lt;/P&gt;&lt;P&gt;Jan 2011&lt;/P&gt;&lt;P&gt;Sep 2011&lt;/P&gt;&lt;P&gt;Mar 2011&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following reports SHOULD be extracted: May 2014, Jun 2013, Aug 2012, Dec 2012, Mar 2011.&lt;/P&gt;&lt;P&gt;However, only the following reports ARE extracted: May 2014, Jun 2013, March 2011.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 04:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218647#M40289</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-26T04:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218648#M40290</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Dr van Straten, didn't you broadcast on LBC some years ago?&amp;nbsp; What a surprise!&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Try this:&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data aborthist;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;set aborthist;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;by descending startdate;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;retain last_kept; /* remember its value from row to row&amp;nbsp; */&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;drop last_kept;&amp;nbsp; /* but do not bother to write it to the output&amp;nbsp; */&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;if _n_=1 then do; /* definitely want the first one */&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_kept = startdate; /* keep a note of the date we just wrote */&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;else if last_kept - startdate ge 180 /* compare current date to last one written */&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then &lt;/SPAN&gt;do;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; last_kept = startdate; /* and this is the one we compare next time */&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;end;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 05:34:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218648#M40290</guid>
      <dc:creator>dkb</dc:creator>
      <dc:date>2015-05-26T05:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218649#M40291</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sorry to disappoint you dkb, I'm not THE Michael van Straten (Health Journalist and much more), I'm just a Michael van Straten (Vet).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your solution. I'll check it out but am already quite confident it will work as you have addressed the key problem. So I know for the future: if one refers to a variable AFTER using the output command (like you did above), will the value of the variable always be that belonging to the observation that was "output"? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 06:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218649#M40291</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-26T06:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218650#M40292</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Worked perfect! Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 06:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218650#M40292</guid>
      <dc:creator>MichaelvanStraten</dc:creator>
      <dc:date>2015-05-26T06:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: A simple macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218651#M40293</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The OUTPUT statement does not change any variable values at all; it just writes the contents of the PDV to the dataset.&lt;/P&gt;&lt;P&gt;Variable values change:&lt;/P&gt;&lt;P&gt;- when an input dataset is read (SET or MERGE statement)&lt;/P&gt;&lt;P&gt;- when values are assigned through direct assignment (=), incrementation (like x + 1;) or by a "call" subroutine&lt;/P&gt;&lt;P&gt;- when a new data step iteration begins (all variables not RETAINED are set to missing)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 26 May 2015 06:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/A-simple-macro/m-p/218651#M40293</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-05-26T06:51:39Z</dc:date>
    </item>
  </channel>
</rss>

