<?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: get the beginning periode of last value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570335#M11937</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;

data want;
do until(last.contract);
set have;
by contract status notsorted;
if first.status then t=periode;
end;
do until(last.contract);
set have;
by contract status notsorted;
if t=periode then output;
end;
drop t;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Obviously, this gives the desired answer, but I'm not understanding the logic here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I comment out the second do-loop, I get the desired answer as well. Am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.contract);
set have;
by contract status notsorted;
if first.status then t=periode;
end;
/*do until(last.contract);*/
/*set have;*/
/*by contract status notsorted;*/
/*if t=periode then output;*/
/*end;*/
/*drop t;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 01 Jul 2019 18:12:03 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-07-01T18:12:03Z</dc:date>
    <item>
      <title>get the beginning period of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570321#M11934</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;

data want;
input contract periode status $ ;
datalines;
111111 201805 B1
222222 201803 B3
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to get the beginning periode of the last value for each contract&lt;/P&gt;
&lt;P&gt;thanks in advance for your help&lt;/P&gt;
&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 19:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570321#M11934</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-07-01T19:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570328#M11935</link>
      <description>&lt;P&gt;To clarify, what you want is to look at the Status at the last Period of the Contract. Then using that Contract and Status you want to look back and find the first Period given that the Status has not changed. In your example, for contract 111111, the first time it has the status B1 is in 201801, but because the Status was B3 in 201804 you are not interested until it becomes B1 and that is where you get the date of 201805. Is my understanding correct?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 17:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570328#M11935</guid>
      <dc:creator>Tommy1</dc:creator>
      <dc:date>2019-07-01T17:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570333#M11936</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;

data want;
do until(last.contract);
set have;
by contract status notsorted;
if first.status then t=periode;
end;
do until(last.contract);
set have;
by contract status notsorted;
if t=periode then output;
end;
drop t;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570333#M11936</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-01T18:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570335#M11937</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;

data want;
do until(last.contract);
set have;
by contract status notsorted;
if first.status then t=periode;
end;
do until(last.contract);
set have;
by contract status notsorted;
if t=periode then output;
end;
drop t;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Obviously, this gives the desired answer, but I'm not understanding the logic here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I comment out the second do-loop, I get the desired answer as well. Am I missing something?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
do until(last.contract);
set have;
by contract status notsorted;
if first.status then t=periode;
end;
/*do until(last.contract);*/
/*set have;*/
/*by contract status notsorted;*/
/*if t=periode then output;*/
/*end;*/
/*drop t;*/
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570335#M11937</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-01T18:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570344#M11938</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; &amp;nbsp;Sir, you are right. But the problem is&lt;/P&gt;
&lt;P&gt;1.The loop doesn't end until it processes one &lt;U&gt;parent&lt;/U&gt; by group , so although T will&amp;nbsp; temporarily hold the correct periode value, we can't have an explicit output for the first of the last sub by group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. More importantly, If we have too many other associated variables for that periode, then that would involve a whole lot gymnastics of&amp;nbsp; from copying and parking in temp vars even if we use an array, which can make it very tedious&lt;/P&gt;
&lt;P&gt;3. So ideally the easy and lazy &lt;U&gt;double&lt;/U&gt; by group pass works best&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570344#M11938</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-01T18:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570346#M11939</link>
      <description>&lt;P&gt;Thank you, all good points. Essentially, your code is more robust to potential real-world possibilities and complications, which the small example presented does not include.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 18:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570346#M11939</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-01T18:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570354#M11940</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Sir, Cheers from Bridgeport,CT. Got into Citizens bank . It's been over a month.&amp;nbsp; Will PM on linkedin or here&amp;nbsp; later &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; While there is this happy career news, I am very broken as my father is very ill&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp; &amp;nbsp;Sir, This thread confirms citizens network works&amp;nbsp; for sas communities as well &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; coz we are SAS citzens first. Thank you for your help. That means a lot.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jul 2019 19:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570354#M11940</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-01T19:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning period of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570381#M11941</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp; Should you have no memory constraints, Hash fun&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;

data _null_ ;
if _n_=1 then do;
   dcl hash H (ordered: "A") ;
   h.definekey  ("contract") ;
   h.definedata ("contract","periode", "status") ;
   h.definedone () ;
end;
do until(last.contract);
set have end=lr;
by contract status notsorted;
if first.status then h.replace();
end;
if lr then h.output(dataset:'want');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jul 2019 20:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570381#M11941</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-01T20:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570447#M11955</link>
      <description>many thanks for your quick response</description>
      <pubDate>Tue, 02 Jul 2019 07:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570447#M11955</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-07-02T07:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570461#M11958</link>
      <description>&lt;P&gt;Hello &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205" target="_self"&gt;&lt;SPAN class="login-bold"&gt;novinosrin&lt;/SPAN&gt;&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks for your help.&lt;/P&gt;&lt;P&gt;may I ask you a subsidiary question.&lt;/P&gt;&lt;P&gt;how to get the before last ?&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 09:18:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570461#M11958</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-07-02T09:18:36Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning periode of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570465#M11959</link>
      <description>&lt;P&gt;sorry,&lt;/P&gt;&lt;P&gt;do not take into account my susidiary question.&lt;/P&gt;&lt;P&gt;I can remove from the dataset all periode greater than last periode.&lt;/P&gt;&lt;P&gt;and then I can re apply your suggested solution&lt;/P&gt;&lt;P&gt;sorry&lt;/P&gt;&lt;P&gt;Nasser&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 09:34:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570465#M11959</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2019-07-02T09:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning period of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570505#M11965</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&amp;nbsp;gave you right code.if period is tied , could try this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input contract periode status $ ;
datalines;
111111 201801 B1
111111 201802 B1
111111 201803 B2
111111 201804 B3
111111 201805 B1
111111 201806 B1
222222 201801 B1
222222 201802 B2
222222 201803 B3
222222 201804 B3
222222 201805 B3
222222 201806 B3
 ;
run;
data want;
do until(last.status);
set have;
by contract status notsorted;
if last.contract then flag=1;
end;
do until(last.status);
set have;
by contract status notsorted;
if first.status and flag then output;
end;
drop flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jul 2019 11:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570505#M11965</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-07-02T11:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning period of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570538#M11969</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp; &amp;nbsp;No wonder my mother thinks you are the best and her favorite!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:01:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570538#M11969</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-07-02T13:01:50Z</dc:date>
    </item>
    <item>
      <title>Re: get the beginning period of last value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570554#M11971</link>
      <description>&lt;P&gt;That is my great honor of all time .&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 13:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/get-the-beginning-period-of-last-value/m-p/570554#M11971</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-07-02T13:37:22Z</dc:date>
    </item>
  </channel>
</rss>

