<?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: Ascending day counter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356751#M83685</link>
    <description>&lt;P&gt;Post enough records of what you want as a result .. enough defined as a sufficient amount that we can understand what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 08 May 2017 00:33:22 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-05-08T00:33:22Z</dc:date>
    <item>
      <title>Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356744#M83679</link>
      <description>&lt;P&gt;Hi SAS Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to write what should be a simple program to capture data with ascending days, eg 01/01/2012 to 01/02/2012.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have done it somewhat, I have created a variable COUNT, which shows me when I have ascending days, however it doesn't give me the origin day eg &amp;nbsp; 12/12/2011 &amp;nbsp;count=0 &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;01/01/2012 count=0 &amp;nbsp;01/02/2012 count=1. As well, I would like to come up with how many ascending days I have consecutively.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I know there must be a loop function to create this but I am not very strong at sas.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any advice would be greatly appreciated.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wcourt.event;

set wcourt.PM25_high;

/*count2=(consec+1);*/
 
tempdate=lag(&amp;amp;start);

leaddate=sum(tempdate,1);

if date=tempdate+1 then count=1;
else count=0;

if leaddate=Date then count2=1;
else count2=0;


/*if count2=1 and count3=*/

format tempdate date9. leaddate date9.;

run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 May 2017 23:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356744#M83679</guid>
      <dc:creator>jorentergesen</dc:creator>
      <dc:date>2017-05-07T23:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356747#M83682</link>
      <description>&lt;P&gt;Look at DIF function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the RETAIN statement to increment counter. It's unclear what you want as output.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll get better answers if you post your data as a data step and show what you want as output. Include it directly in the forum - not as an attachment.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 00:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356747#M83682</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-08T00:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356749#M83683</link>
      <description>&lt;P&gt;Early in your code you use:&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;tempdate&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;lag&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;start&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Where do you create the macro variable start and what is its value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 00:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356749#M83683</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-08T00:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356750#M83684</link>
      <description>&lt;P&gt;Oh sorry I thought I took that out. &amp;nbsp;&amp;amp;start=Date&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;

data wcourt.event;

set wcourt.PM25_high;

/*count2=(consec+1);*/
 
tempdate=lag(Date);

leaddate=sum(tempdate,1);

if date=tempdate+1 then count=1;
else count=0;
retain count;

if leaddate=Date then count2=1;
else count2=0;


/*if count2=1 and count3=*/

format tempdate date9. leaddate date9.;

run;quit;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 00:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356750#M83684</guid>
      <dc:creator>jorentergesen</dc:creator>
      <dc:date>2017-05-08T00:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356751#M83685</link>
      <description>&lt;P&gt;Post enough records of what you want as a result .. enough defined as a sufficient amount that we can understand what you are trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 00:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356751#M83685</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-08T00:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356753#M83686</link>
      <description>&lt;P&gt;The data looks like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date,Mean&lt;/P&gt;&lt;P&gt;01/01/2012,xx&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/05/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/08/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/09/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/11/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/23/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/24/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/25/2012,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02/01/2013,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02/09/2013,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/01/2014,xx&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want my data output to have this: The date, the mean, if the day is apart of ascending days in order, the numbers of days ascending&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Date,Mean,Ascending_days_occurence,#_of_ascending_days&lt;/P&gt;&lt;P&gt;01/01/2012,xx,0,0&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/05/2012,xx,0,0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/08/2012,xx,1,1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/09/2012,xx,1,2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/11/2012,xx0,0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/23/2012,xx1,1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/24/2012,xx1,2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/25/2012,xx1,3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02/01/2013,xx,0,0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;02/09/2013,xx,0,0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01/01/2014,xx,0,0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 00:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356753#M83686</guid>
      <dc:creator>jorentergesen</dc:creator>
      <dc:date>2017-05-08T00:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356755#M83687</link>
      <description>&lt;P&gt;If all you are looking for is a consecutive days counter then the following would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data wcourt.event (drop=date2);
  merge wcourt.PM25_high wcourt.PM25_high (firstobs=2 keep=date rename=(date=date2));
  if _n_ eq 1 then count=0;
  if dif(date) eq 1 or date+1 eq date2 then count+1;
  else count=0;
  output;
  if date+1 ne date2 then count=0;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 01:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356755#M83687</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-08T01:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356759#M83689</link>
      <description>&lt;P&gt;I know this may be annoying but do you mind explaining what "_n_" does?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 01:46:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356759#M83689</guid>
      <dc:creator>jorentergesen</dc:creator>
      <dc:date>2017-05-08T01:46:40Z</dc:date>
    </item>
    <item>
      <title>Re: Ascending day counter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356778#M83702</link>
      <description>&lt;P&gt;_n_, in a datastep, is the automatic record counter. Thus, for record 1, _n_ equals 1, for record 2 it equals 2, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 May 2017 04:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Ascending-day-counter/m-p/356778#M83702</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-08T04:53:57Z</dc:date>
    </item>
  </channel>
</rss>

