<?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 First. and last. woes in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544003#M7784</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really annoyed with myself that I can't figure this out (or find the answer online). I have a dataset that covers the last four years (a single month end entry for each account) of accounts moving through arrears cycles and I am trying to identify the first and last occurrence of each account being at each level of arrears cycle so I can calculate how long an account has spent at a particular level of arrears cycles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have sorted the dataset by account_no, month and cycle&amp;nbsp;and thought I would be able to use a by statement in my data step to say&lt;/P&gt;&lt;P&gt;by account_no date cycle and then say if first.cycle or last.cycle then cycle_flag = 1. When I've run this, every entry has a cycle_flag of 1 which I assume is because each month entry is unique so it is the first. combination of the three variables. If I try to say just by account_no and cycle, then I get an error message saying the by variables are not properly sorted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="1"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;=all_roller;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; account_no month current_cycle;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; all_roller_1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; all_roller;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; account_no month current_cycle;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; first.current_cycle &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;or&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; last.current_cycle &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; cyc_flag = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; cyc_flag = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do need the data to be sorted by date so am looking for help in how to pull out&amp;nbsp;the first and last entries of each cycle amount. If an account has been at cycle level 3 then goes to 4 and then back to 3 at a later date, I would be looking to flag up the cycle level three on more than one occasion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, thanks in advance for any assistance,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2019 15:01:23 GMT</pubDate>
    <dc:creator>robulon</dc:creator>
    <dc:date>2019-03-18T15:01:23Z</dc:date>
    <item>
      <title>First. and last. woes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544003#M7784</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Really annoyed with myself that I can't figure this out (or find the answer online). I have a dataset that covers the last four years (a single month end entry for each account) of accounts moving through arrears cycles and I am trying to identify the first and last occurrence of each account being at each level of arrears cycle so I can calculate how long an account has spent at a particular level of arrears cycles.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have sorted the dataset by account_no, month and cycle&amp;nbsp;and thought I would be able to use a by statement in my data step to say&lt;/P&gt;&lt;P&gt;by account_no date cycle and then say if first.cycle or last.cycle then cycle_flag = 1. When I've run this, every entry has a cycle_flag of 1 which I assume is because each month entry is unique so it is the first. combination of the three variables. If I try to say just by account_no and cycle, then I get an error message saying the by variables are not properly sorted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="1"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;=all_roller;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; account_no month current_cycle;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; all_roller_1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; all_roller;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; account_no month current_cycle;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; first.current_cycle &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;or&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; last.current_cycle &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;then&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; cyc_flag = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="1"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt; cyc_flag = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="1"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="1"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="1"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do need the data to be sorted by date so am looking for help in how to pull out&amp;nbsp;the first and last entries of each cycle amount. If an account has been at cycle level 3 then goes to 4 and then back to 3 at a later date, I would be looking to flag up the cycle level three on more than one occasion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As always, thanks in advance for any assistance,&lt;/P&gt;&lt;P&gt;Rob&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544003#M7784</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2019-03-18T15:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. woes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544005#M7785</link>
      <description>&lt;P&gt;Please show us a representative portion of your data, as &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_self"&gt;SAS data step code&lt;/A&gt; (and not in some other format).&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:07:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544005#M7785</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-03-18T15:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. woes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544015#M7787</link>
      <description>&lt;P&gt;If you want to use FIRST./LAST. processing on data that is not sorted then add the NOTSORTED keyword to the BY statement.&lt;/P&gt;
&lt;P&gt;This will treat the data as grouped, but not check if the groups are ordered.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data all_roller_1;
  set all_roller;
  by account_no current_cycle notsorted;
  if first.current_cycle or last.current_cycle then cyc_flag = 1;
 else cyc_flag = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that if the group only has only one or two observations then all of the observations in that group will have CYR_FLAG=1.&amp;nbsp; When the group has more than two observations then the "middle" observations will have CYR_FLAG=0.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544015#M7787</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-18T15:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. woes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544017#M7788</link>
      <description>&lt;P&gt;Apologies Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so in the example below, I'd be looking for the flag variable to be created for JAN2015 (first), MAR2015 (last), APR2015(first &amp;amp; last), MAY2015 (first),DEC2016 (last), JAN2017(first &amp;amp; last)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data WORK.ALL_ROLLER_1;&lt;/P&gt;&lt;P&gt;infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;input month:MONYY7. account_no:32. current_cycle:32.;&lt;/P&gt;&lt;P&gt;format month MONYY7.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;JAN2015 8552 1&lt;/P&gt;&lt;P&gt;FEB2015 8552 1&lt;/P&gt;&lt;P&gt;MAR2015 8552 1&lt;/P&gt;&lt;P&gt;APR2015 8552 0&lt;/P&gt;&lt;P&gt;JUL2015 8552 1&lt;/P&gt;&lt;P&gt;AUG2015 8552 1&lt;/P&gt;&lt;P&gt;SEP2015 8552 1&lt;/P&gt;&lt;P&gt;OCT2015 8552 1&lt;/P&gt;&lt;P&gt;NOV2015 8552 1&lt;/P&gt;&lt;P&gt;DEC2015 8552 1&lt;/P&gt;&lt;P&gt;JAN2016 8552 1&lt;/P&gt;&lt;P&gt;FEB2016 8552 1&lt;/P&gt;&lt;P&gt;MAR2016 8552 1&lt;/P&gt;&lt;P&gt;APR2016 8552 1&lt;/P&gt;&lt;P&gt;MAY2016 8552 1&lt;/P&gt;&lt;P&gt;JUN2016 8552 1&lt;/P&gt;&lt;P&gt;JUL2016 8552 1&lt;/P&gt;&lt;P&gt;AUG2016 8552 1&lt;/P&gt;&lt;P&gt;SEP2016 8552 1&lt;/P&gt;&lt;P&gt;OCT2016 8552 1&lt;/P&gt;&lt;P&gt;NOV2016 8552 1&lt;/P&gt;&lt;P&gt;DEC2016 8552 1&lt;/P&gt;&lt;P&gt;JAN2017 8552 0&lt;/P&gt;&lt;P&gt;;;;;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544017#M7788</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2019-03-18T15:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: First. and last. woes</title>
      <link>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544020#M7789</link>
      <description>&lt;P&gt;That's perfect, thanks Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't believe I've never come across notsorted before, definitely will be a lot of use to me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2019 15:42:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/First-and-last-woes/m-p/544020#M7789</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2019-03-18T15:42:29Z</dc:date>
    </item>
  </channel>
</rss>

