<?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: How to derive these column E and F(excel) in SAS? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688957#M37183</link>
    <description>&lt;P&gt;I don't see any need to look ahead in the photo you just posted.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Oct 2020 17:34:50 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-10-05T17:34:50Z</dc:date>
    <item>
      <title>How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688867#M37168</link>
      <description>&lt;P&gt;Hello i would like to derive column E and F in SAS. I have done it via Excel and this is as follows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column E: =IF(D2=1,1,IF(OR(C2=1,A2&amp;lt;&amp;gt;A1),"",E1))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Column F: =IF(AND(E1="",E2=1),B2,IF(AND(E2=1,E1=1),IF(B2&amp;gt;F1,B2,F1),""))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="help.jpg" style="width: 623px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50161iA1F30539311A5660/image-size/large?v=v2&amp;amp;px=999" role="button" title="help.jpg" alt="help.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 13:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688867#M37168</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-05T13:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688893#M37172</link>
      <description>&lt;P&gt;Speaking as someone who is not particularly good at Excel, I can't really interpret your Excel code, but ... YOU can! Write down your code in plain English as IF THEN statements, and show us those. From there, show your plain English to us. It should be relatively easy to translate plain English IF THEN statements into SAS IF THEN statements.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 14:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688893#M37172</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-05T14:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688904#M37173</link>
      <description>&lt;P&gt;Like &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;suggested, converting your Excel formulas to plain English is a good first step.&amp;nbsp; As another approach, I attempted to convert your formulas to pseudo-code.&amp;nbsp; You can revise it if there are any errors.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if D2 = 1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; then column_E = "1"&lt;/P&gt;
&lt;P&gt;else if C2 = 1 or A2 ne A1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; then column_E = " "&lt;/P&gt;
&lt;P&gt;else column_E = E1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if (E1 = " " and E2 = 1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; then column_F = B2&lt;/P&gt;
&lt;P&gt;else if (E2 = 1 and E1 = 1)&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; then do&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if B2 &amp;gt; F1 then column_F = B2&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else column_F = F1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; end&lt;/P&gt;
&lt;P&gt;else column_F = " "&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(As a side note, make sure the formulas correspond to the data you provided.&amp;nbsp; The formulas you included reference cells in row 1, which contains the headers (e.g. E1 is NEW FLAG).&amp;nbsp; I don't think you intended those to be part of it.)&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:36:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688904#M37173</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-05T15:36:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688906#M37174</link>
      <description>&lt;P&gt;Ah okay! So for Column E, the new flag column is derived basing on Column D the flag column. As long as there's a flag indicator where Column D hits 1, it will carry forward to subsequent rows in Column E until the point where Column C becomes 1 or when Column A is a new account number. It will loop and check for column D whether there's a flag for 1 and then once hit, it will add 1 to that row and the subsequent rows in Column E. I tried looking up and using the LAG function but it does not seems to work in this scenario.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Column F, it's slightly more complicated where at the very first instance when Column E (derived above) has a flag 1, we will take that row $ Amt in Column B. For the subsequent rows, we are required to compare the newly derived amount in Column F with Column B, the higher of the two prevails and will be the new value in Column F which can be seen in the image uploaded.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688906#M37174</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-05T15:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688907#M37175</link>
      <description>&lt;P&gt;Hi thanks for the replies guys! Really appreciate it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For SAS, unfortunately there's no cell reference like what I can do in Excel. Not sure if you have any idea how we can compare a single cell record in SAS with the subsequent records? I have tried using LAG in SAS but it's only able to compare previous record for Column B. For my case i will need a dynamic LAG to compare with my newly derived values in Column F against Column B row value.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688907#M37175</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-05T15:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688911#M37176</link>
      <description>&lt;P&gt;You do have column names: accno, amt, sequence and flag. Use these, and add "from previous row" or "from first row in group" where adequate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also describe your algorithm this way:&lt;/P&gt;
&lt;P&gt;"in the first row of each accno I want to do X, in the next row I want to do Y, in subsequent rows I want to do Z".&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688911#M37176</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-05T15:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688912#M37177</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350780"&gt;@sas_newbie94&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi thanks for the replies guys! Really appreciate it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For SAS, unfortunately there's no cell reference like what I can do in Excel. Not sure if you have any idea how we can compare a single cell record in SAS with the subsequent records? I have tried using LAG in SAS but it's only able to compare previous record for Column B. For my case i will need a dynamic LAG to compare with my newly derived values in Column F against Column B row value.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;RETAIN would likely be a better approach. That makes a variable whose values are maintained across iterations of the data step. You have to set the value for the retained value, likely copying an existing variable to the retained one as needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A not particularly useful example of the syntax where the Retain statement sets an initial value:&lt;/P&gt;
&lt;PRE&gt;data work.class;
   set sashelp.class;
   retain beforejane 'Yes';
   if name='Jane' then beforejane='No';
run;&lt;/PRE&gt;
&lt;P&gt;You should specify a length for retained character variables before the retain statement if you do not initialize them, or the initial value is shorter than some expected values that need to be assigned.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 15:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688912#M37177</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-05T15:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688924#M37178</link>
      <description>&lt;P&gt;Thanks for the tips!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the first derived column, [NEW FLAG; Column E]:&lt;/P&gt;&lt;P&gt;In the first row of each account number (Column A), if there's no flag indication with the value 1 (Column D), my newly derived value (Column E) will be a blank. If an account number has an indication of value 1 (Column D). my new Flag column will inherit the value of 1 (Column E). This value will be inherited to subsequent rows with the value of 1 until there's a new account number (it will stop inheriting the value of 1 and check for the new account number if there's an indication of value 1 (Column D) again, in a way it will be 'resetted') OR if it's the same account number, the Sequence column (Column C) indicates a 1, this will also 'reset' the check and stop inheriting the value of 1 until there's a flag indication with the value of 1 (Column D) again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the second derived column, [NEW $ AMT; Column F]:&lt;/P&gt;&lt;P&gt;This part it will tend to be slightly trickier. In the first row where it's either a new accno OR same accno but sequence of 1, where the NEW FLAG Column E has a value of 1, we will take the first $ Amt and placed it under NEW $AMT which can be seen highlighted in yellow. For subsequent rows, the newly derived value in Column F we will have to compare with Column B and take the higher of the two which can be seen in the image attached.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="help2.jpg" style="width: 707px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50165i01B22BB8FBF03A82/image-size/large?v=v2&amp;amp;px=999" role="button" title="help2.jpg" alt="help2.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:20:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688924#M37178</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-05T16:20:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688930#M37179</link>
      <description>&lt;P&gt;I think this will get you started. Note that the important part is the "retain" statement; it allows carrying a result forward. See if this is going in the direction you want, and we can keep working on it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
	input AccNo AMT Sequence FLAG;
	cards;
1 111663 29 .
1 111663 30 .
1 111663 31 1
1 111663 32 .
1 111663 1 .
1 111663 2 1
2 111663 1 1
3 111663 1 .
3 111663 2 1
run;

data Want;
	set Have;
	retain OldAcc . Switch 0 NEWFLAG . NEWAMT .;

	if AccNo &amp;gt; OldAcc | Sequence = 1 then
		Switch = 0;

	if FLAG = 1 then
		Switch = 1;

	if Switch = 1 then
		do;
			NEWFLAG = 1;
			NEWAMT = AMT;
		end;
	else
		do;
			NEWFLAG = .;
			NEWAMT = .;
		end;

	OldAcc = AccNo;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688930#M37179</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2020-10-05T16:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688933#M37180</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350780"&gt;@sas_newbie94&lt;/a&gt;&amp;nbsp; &amp;nbsp;Give this a try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    infile datalines missover;
    input accNo AMT Sequence Flag;
    datalines;
    1 111663 29  
    1 111760 30  
    1 111986 31 1
    1 108676 32  
    1 108774 33  
    1 108348 34  
    1 269278 35  
    1 269004 36  
    1 265680 1   
    1 265120 2  1
    1 264504 3   
    1 263420 4   
    2 194655 1  1
    3 114645 1   
    3 114378 2  1
    3 200000 3   
    3 15000 4    
    ;
run;


options mprint;
data want (drop=start x y);
    set have;
    retain start y;

    /* New_Flag logic */
    if flag = 1
        then do;
            new_flag = 1;
            start = 1;
        end;
    else if sequence = 1 or accNo ne lag(accNo)
        then do;
            new_flag = .;
            start = 0;
        end;
    else if start = 1
        then new_flag = 1;
    else new_flag = lag(new_flag);

    x = new_flag;

    /* New_Amt logic */
    if x = . and new_flag = 1
        then new_amt = amt;
    else if (new_flag = 1 and x = 1)
        then new_amt = max(amt, y);
    else new_amt = .;

    y = new_amt;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mklangley_0-1601915755728.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50168iAC358B4F13D2CC51/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mklangley_0-1601915755728.png" alt="mklangley_0-1601915755728.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 16:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688933#M37180</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-05T16:36:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688949#M37181</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223296"&gt;@mklangley&lt;/a&gt; for your help! It's really close to getting the desired output! However apologies i may have flagged incorrectly for one of the rows for New $ Amt (Column F) which I have corrected the values and highlighted in green. Since it's a new account number, it should take the $ Amt at Column B as the NEW $ Amt and not the prior $ Amt from Account 1. Thankful for your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="help4.jpg" style="width: 707px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50171i8426D584E57C6DB1/image-size/large?v=v2&amp;amp;px=999" role="button" title="help4.jpg" alt="help4.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_newbie94_0-1601917335248.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50172iD00EA337B7F12454/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_newbie94_0-1601917335248.png" alt="sas_newbie94_0-1601917335248.png" /&gt;&lt;/span&gt;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688949#M37181</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-05T17:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688952#M37182</link>
      <description>&lt;P&gt;Okay, how about this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
data want (drop=start x y);
    set have;
    retain start y;

    /* New_Flag logic */
    if flag = 1
        then do;
            new_flag = 1;
            start = 1;
        end;
    else if sequence = 1 or accNo ne lag(accNo)
        then do;
            new_flag = .;
            start = 0;
        end;
    else if start = 1
        then new_flag = 1;

    x = new_flag;

    /* New_Amt logic */
    if x = . and new_flag = 1
        then new_amt = amt;
    else if (new_flag = 1 and x = 1 and accNo = lag(accNo))
        then new_amt = max(amt, y);
    else if (new_flag = 1 and x = 1 and accNo ne lag(accNo))
        then new_amt = amt;
    else new_amt = .;

    y = new_amt;
run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688952#M37182</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-05T17:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688957#M37183</link>
      <description>&lt;P&gt;I don't see any need to look ahead in the photo you just posted.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688957#M37183</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-05T17:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688960#M37184</link>
      <description>&lt;P&gt;It looks like you are tying to calculate a running MAX() of the AMT variable per ACCNO, but you have to wait to start until you see the race director drop the FLAG.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  by accno;
  if first.accno then call missing(start_counting,max_amt);
  start_counting=max(start_counting,flag);
  if start_counting then max_amt = max(amt,max_amt);
  retain start_counting max_amt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For tested code you need to post your example data as code instead of photographs.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Oct 2020 17:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/688960#M37184</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-05T17:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689131#M37190</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223296"&gt;@mklangley&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your prompt replies and speedy updates. Your code is really good and I appreciate your help. However, I realised that I have another scenario where there's another logic to deriving new $ AMT column F. I would like to seek your help once again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Column F, new $ Amt, at the first time where Column D hits a value of 1, it will take the $ AMT for that row and inherit across subsequent rows until it hits another value of 1 in column D flag, that's where we will compare the two $ AMT and take the higher of the two. Take note that the new $ AMT needs to only be included for new flag = 1 and do the checks accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired Output as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_newbie94_0-1601977737327.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50204i6AEB4EF6693CB6AD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_newbie94_0-1601977737327.png" alt="sas_newbie94_0-1601977737327.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 09:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689131#M37190</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-06T09:52:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689136#M37192</link>
      <description>&lt;P&gt;Please post your data in a data step with datalines, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223296"&gt;@mklangley&lt;/a&gt;&amp;nbsp;has already shown. We cannot test SAS code against pictures. Data steps with datalines are not rocket science, but a very useful skill, and help greatly in illustrating issues.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 10:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689136#M37192</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-06T10:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689138#M37194</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the replies.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please find below information which you require:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines missover;&lt;BR /&gt;input accNo AMT Sequence Flag;&lt;BR /&gt;datalines;&lt;BR /&gt;1 111663 29&lt;BR /&gt;1 111760 30&lt;BR /&gt;1 111986 31 1&lt;BR /&gt;1 108676 32&lt;BR /&gt;1 108774 33&lt;BR /&gt;1 269278 34 1&lt;BR /&gt;1 269278 35&lt;BR /&gt;1 269004 36&lt;BR /&gt;1 265680 1&lt;BR /&gt;1 265120 2 1&lt;BR /&gt;1 264504 3&lt;BR /&gt;1 263420 4&lt;BR /&gt;2 194655 1 1&lt;BR /&gt;3 114645 1&lt;BR /&gt;3 114378 2 1&lt;BR /&gt;3 200000 3&lt;BR /&gt;3 15000 4&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;options mprint;
data want (drop=start x);
    set have;
    retain start;

    /* New_Flag logic */
    if flag = 1
        then do;
            new_flag = 1;
            start = 1;
        end;
    else if sequence = 1 or accNo ne lag(accNo)
        then do;
            new_flag = .;
            start = 0;
        end;
    else if start = 1
        then new_flag = 1;

    x = new_flag;
run;

proc print; run;&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 06 Oct 2020 10:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689138#M37194</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-06T10:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689143#M37197</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
input accNo AMT Sequence Flag;
datalines;
1 111663 29
1 111760 30
1 111986 31 1
1 108676 32
1 108774 33
1 269278 34 1
1 269278 35
1 269004 36
1 265680 1
1 265120 2 1
1 264504 3
1 263420 4
2 194655 1 1
3 114645 1
3 114378 2 1
3 200000 3
3 15000 4
;

data want;
set have;
by accno;
retain newflag newamt;
if first.accno or sequence = 1
then do;
  newflag = .;
  newamt = .;
end;
if flag = 1
then do;
  newflag = 1;
  newamt = amt;
end;
if newamt ne . then newamt = max(amt,newamt);
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;accNo	AMT	Sequence	Flag	newflag	newamt
1	111663	29	.	.	.
1	111760	30	.	.	.
1	111986	31	1	1	111986
1	108676	32	.	1	111986
1	108774	33	.	1	111986
1	269278	34	1	1	269278
1	269278	35	.	1	269278
1	269004	36	.	1	269278
1	265680	1	.	.	.
1	265120	2	1	1	265120
1	264504	3	.	1	265120
1	263420	4	.	1	265120
2	194655	1	1	1	194655
3	114645	1	.	.	.
3	114378	2	1	1	114378
3	200000	3	.	1	200000
3	15000	4	.	1	200000
&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Oct 2020 10:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689143#M37197</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-06T10:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689151#M37198</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;. , thanks for the replies. However for the ones highlighted, it appears incorrect. It should show 114378 for subsequent rows as the flag of value 1 hits and subsequent rows should inherit that value until it either hits a new account or within the same account, a new sequence of 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="photo_2020-10-06_19-02-55.jpg" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50207i8879F739BFCBA343/image-size/medium?v=v2&amp;amp;px=400" role="button" title="photo_2020-10-06_19-02-55.jpg" alt="photo_2020-10-06_19-02-55.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sas_newbie94_0-1601982360747.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50208i28D2ED81B42D7852/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sas_newbie94_0-1601982360747.png" alt="sas_newbie94_0-1601982360747.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 11:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689151#M37198</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-06T11:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to derive these column E and F(excel) in SAS?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689156#M37199</link>
      <description>&lt;P&gt;For further clarity here's a sample data which i have tweak the numbers abit:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data have;
infile datalines missover;
input accNo AMT Sequence Flag;
datalines;
1 111663 29
1 111760 30
1 111986 31 1
1 500000 32
1 500000 33
1 269278 34 1
1 500000 35
1 500000 36
1 265680 1
1 265120 2 1
1 500000 3
1 500000 4
2 194655 1 1
3 114645 1
3 114378 2 1
3 500000 3
3 500000 4
;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the new amount indicator, I will only take the higher of the two between the first time it hits a value of 1 in the same account and the subsequent time it hits a value of 1 in the Flag column. If there's no 2nd hit of value of 1 in the same account, it will retain the value of 1 initially flagged.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Desired Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Annotation 2020-10-06 191431.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50209i85671C70BE852D01/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Annotation 2020-10-06 191431.png" alt="Annotation 2020-10-06 191431.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;DIV class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 11:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-derive-these-column-E-and-F-excel-in-SAS/m-p/689156#M37199</guid>
      <dc:creator>sas_newbie94</dc:creator>
      <dc:date>2020-10-06T11:15:33Z</dc:date>
    </item>
  </channel>
</rss>

