<?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: Formula Help in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735600#M229155</link>
    <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasuser_sk_0-1618930808406.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58374iB0588E5AC55980CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasuser_sk_0-1618930808406.png" alt="sasuser_sk_0-1618930808406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Apr 2021 15:00:51 GMT</pubDate>
    <dc:creator>sasuser_sk</dc:creator>
    <dc:date>2021-04-20T15:00:51Z</dc:date>
    <item>
      <title>Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735575#M229148</link>
      <description>&lt;P&gt;Hello Everyone - I'm looking for some help in writing the formula given below in sas. Please advise. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if(Duplicate !=null &amp;amp;&amp;amp; Product != Next(Product)) then "Delete"&lt;/P&gt;
&lt;P&gt;if(Duplicate !=null &amp;amp;&amp;amp; Product = 'CLOSED' &amp;amp;&amp;amp; Next(Product) = 'CLOSED') then "Delete"&lt;/P&gt;
&lt;P&gt;else " "&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735575#M229148</guid>
      <dc:creator>sasuser_sk</dc:creator>
      <dc:date>2021-04-20T14:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735578#M229149</link>
      <description>&lt;P&gt;"Delete" as you are using it should not be in quotes, unless I am mis-understanding what you are doing. What are you trying to do with "Delete"??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you use NULL, do you really mean checking for SAS missing values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why don't you have semi-colons at the end of each line?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Why the double-ampersands? I know MATLAB uses double-ampersands to have specific meaning, SAS does not.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:34:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735578#M229149</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-20T14:34:51Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735585#M229151</link>
      <description>&lt;P&gt;&lt;STRONG&gt;This code/formula is not form SAS but from Hyperion&lt;/STRONG&gt;. I'm trying to figure out the same formula in SAS. I edited it a bit to show what I intend to achieve in SAS.&lt;/P&gt;
&lt;P&gt;I'm creating a new column with this formula. Delete is just an indicator in this new column that I will filter out later. It could be 0 or remove instead of Delete.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By &lt;STRONG&gt;!null&lt;/STRONG&gt; I means if Duplicate is not missing.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735585#M229151</guid>
      <dc:creator>sasuser_sk</dc:creator>
      <dc:date>2021-04-20T14:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735589#M229152</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311117"&gt;@sasuser_sk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello Everyone - I'm looking for some help in writing the formula given below in sas. Please advise. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if(Duplicate !=null &amp;amp;&amp;amp; Product != Next(Product)) then "Delete"&lt;/P&gt;
&lt;P&gt;if(Duplicate !=null &amp;amp;&amp;amp; Product = 'CLOSED' &amp;amp;&amp;amp; Next(Product) = 'CLOSED') then "Delete"&lt;/P&gt;
&lt;P&gt;else " "&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, what does that "formula" do? Provide example data of start and end result.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 14:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735589#M229152</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-20T14:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735600#M229155</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasuser_sk_0-1618930808406.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58374iB0588E5AC55980CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasuser_sk_0-1618930808406.png" alt="sasuser_sk_0-1618930808406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 15:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735600#M229155</guid>
      <dc:creator>sasuser_sk</dc:creator>
      <dc:date>2021-04-20T15:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735638#M229168</link>
      <description>&lt;P&gt;I think this gives you what you want. I would recommend making a snippet of data available for us in the form of a 'have' data set and a 'want' data set. It makes it a lot easier than eyeballing an excel screenshot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know if this is how your data is structured either. Things may change depending on what you have as well as additional records.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id duplicate product :$6.;
datalines;
7448 0 CLOSED
7448 . ACTIVE
71802 . ACTIVE
73627 0 CLOSED
73627 . ACTIVE
72092 0 CLOSED
72092 . ACTIVE
701992 . ACTIVE
7282 0 CLOSED
7282 0 CLOSED
7282 . ACTIVE
7363 0 CLOSED
7363 . ACTIVE
739 0 CLOSED
739 . CLOSED
;
run;

proc sort data = have;
	by id duplicate;
run;


data want;
	set have;
	by id;
	lag_product = lag(product);
		if first.id then call missing(lag_product);
		if not missing(duplicate) and product ^= lag_product then want_column = "delete";
			else if not missing(duplicate) and (product = "CLOSED" and lag_product = "CLOSED") then want_column = "delete";
				else call missing(want_column);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs id duplicate product lag_product want_column 
1 739 . CLOSED     
2 739 0 CLOSED CLOSED delete 
3 7282 . ACTIVE     
4 7282 0 CLOSED ACTIVE delete 
5 7282 0 CLOSED CLOSED delete 
6 7363 . ACTIVE     
7 7363 0 CLOSED ACTIVE delete 
8 7448 . ACTIVE     
9 7448 0 CLOSED ACTIVE delete 
10 71802 . ACTIVE     
11 72092 . ACTIVE     
12 72092 0 CLOSED ACTIVE delete 
13 73627 . ACTIVE     
14 73627 0 CLOSED ACTIVE delete 
15 701992 . ACTIVE     

&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Apr 2021 16:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735638#M229168</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-04-20T16:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735655#M229170</link>
      <description>&lt;P&gt;It's possible your logic is more complicated but right now that could be simplified to delete all CLOSED + DUPLICATE records.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you please show a case where you have a CLOSED record that is not deleted?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if duplicate = 0 and product = "CLOSED" then new_column = "DELETE";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311117"&gt;@sasuser_sk&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasuser_sk_0-1618930808406.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58374iB0588E5AC55980CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasuser_sk_0-1618930808406.png" alt="sasuser_sk_0-1618930808406.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 16:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735655#M229170</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-20T16:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735664#M229171</link>
      <description>&lt;P&gt;Reeza, after creating the new_column I have to make further comparisons to several other fields (ex: dates) based on this new column and build logic on the gaps between the closed products. That would be my next step after I create this new column.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to break steps into smaller formulas to avoid creating complex ones.&lt;/P&gt;
&lt;P&gt;Building looped formula makes it difficult (for me) to figure out what is working or not.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sasuser_sk_0-1618937203778.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/58400i803AB25A69D406A6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sasuser_sk_0-1618937203778.png" alt="sasuser_sk_0-1618937203778.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Apr 2021 16:47:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735664#M229171</guid>
      <dc:creator>sasuser_sk</dc:creator>
      <dc:date>2021-04-20T16:47:43Z</dc:date>
    </item>
    <item>
      <title>Re: Formula Help</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735688#M229177</link>
      <description>I think you're using Excel logic in SAS and it's taking you a long way around doing something that would be likely easier in SAS using native functionality.&lt;BR /&gt;&lt;BR /&gt;And please don't post anymore screenshots, post your data as text which makes it easier to use your data to help answer your questions.</description>
      <pubDate>Tue, 20 Apr 2021 17:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formula-Help/m-p/735688#M229177</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-20T17:32:35Z</dc:date>
    </item>
  </channel>
</rss>

