<?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 compare values within an ID in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547619#M33338</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot. I probably have not expressed myself right... In your output, from line 3 to 4 and from line 4 to 5, Inventory is increasing, but AsendingFlag did not identify them as 1... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Apr 2019 13:45:13 GMT</pubDate>
    <dc:creator>Yiting</dc:creator>
    <dc:date>2019-04-01T13:45:13Z</dc:date>
    <item>
      <title>How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546147#M33305</link>
      <description>&lt;P&gt;In Enterprise Guide, if I have a table like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;REGIO&lt;/TD&gt;&lt;TD&gt;GESLACHT&lt;/TD&gt;&lt;TD&gt;VOORLETTERS&lt;/TD&gt;&lt;TD&gt;XXX_REGIO&lt;/TD&gt;&lt;TD&gt;XXX_GESLACHT&lt;/TD&gt;&lt;TD&gt;XXX_VOORLETTERS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;R.H.M.&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;R.H.L.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;D.A.&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;D.A.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A.&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;S.B.M.J.&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;S.B.M.K.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have sorted by GESLACHT (first) and REGIO (which is a time variable) (second) and then within each value of GESLACHT, I want to see if its&amp;nbsp;VOORLETTERS is increasing or decreasing. I want an extra column to indicate this. If given a GESLACHt, its&amp;nbsp;VOORLETTERS is always increasing, give all the rows with this GESLACHT 1 and otherwise, 0 in the extra column. How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Sorry I stole the table from another user, but the question is different).&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546147#M33305</guid>
      <dc:creator>Yiting</dc:creator>
      <dc:date>2019-03-26T14:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546159#M33306</link>
      <description>&lt;P&gt;There's something contradictory in your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First you say, "I have sorted by GESLACHT (first) and VOORLETTERS (second)".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you say, "within each value of GESLACHT, I want to see if its VOORLETTERS is increasing or decreasing".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have sorted by VOORLETTERS, they will always be ascending, won't they?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps a different example would make it clearer to us.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Tom&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:23:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546159#M33306</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-03-26T14:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546162#M33307</link>
      <description>&lt;P&gt;You are very right! I have changed the variables sorted. Could you have a look at it again? Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 14:27:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546162#M33307</guid>
      <dc:creator>Yiting</dc:creator>
      <dc:date>2019-03-26T14:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546197#M33308</link>
      <description>&lt;P&gt;Makes a little more sense! To have something I could test, I used sashelp.cars, and substituted&amp;nbsp;REGION, PRODUCT, and INVENTORY for GESLACHT, REGIO, and VOORLETTERS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The PROC SORT at the start isn't part of the solution, it just gets the data in the right sequence.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This isn't exhaustively tested, so make sure it's actually doing what you want!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Tom&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.shoes out=work.Have(keep=REGION PRODUCT INVENTORY);
	by REGION PRODUCT;
run;

data Inter01;
	keep REGION PRODUCT AscendingFlag;
	retain OldINVENTORY AscendingFlag;
	set Have;
	by REGION PRODUCT;

	if first.PRODUCT then
		do;
			OldINVENTORY=.;
			AscendingFlag=1;
		end;

	if INVENTORY &amp;gt; OldINVENTORY then;
	else
		AscendingFlag=0;
	OldINVENTORY=INVENTORY;

	if last.PRODUCT then
		output;
run;

proc sql;
	create table Want as select h.*, f.AscendingFlag from Have h inner join 
		Inter01 f on(h.REGION=f.REGION and h.PRODUCT=f.PRODUCT);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Mar 2019 15:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546197#M33308</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-03-26T15:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546353#M33309</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189396"&gt;@Yiting&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to sort by GESLACHT, VOORLETTERS, &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;REGIO&lt;/FONT&gt; &lt;/STRONG&gt;to guarantee that the sort order within a GESLACHT/VOORSLETTERS tuple remains in the required sequence for your analysis.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Mar 2019 23:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546353#M33309</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-03-26T23:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546773#M33312</link>
      <description>&lt;P&gt;Here's an approach. It's somewhat similar to the&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15142"&gt;@TomKari&lt;/a&gt;&amp;nbsp;suggestion, but uses your data and your variables.&amp;nbsp; First:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
   by geslacht regio;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then check for ascending values (top DO loop) and output the results (bottom DO loop).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   ascending=1;
   do until (last.geslacht);
      set have;
      by geslacht;
      if voorletters &amp;lt;= prior_voorletters then ascending=0;
      prior_voorletters = voorletters;
   end;
   do until (last.geslacht);
      set have;
      by geslacht;
      output;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This logic assumes that equal values fail on the "ascending" test.&amp;nbsp; If you want to allow equal values as part of an ascending pattern, you can change the comparison ( &amp;lt;= would become &amp;lt; instead).&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 02:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/546773#M33312</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-03-28T02:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547138#M33324</link>
      <description>&lt;P&gt;Hi, thank a lot! but I am still trying to understand&amp;nbsp;OldINVENTORY variable. How was it defined? Why does it not appear in the Inter01 table?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 10:33:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547138#M33324</guid>
      <dc:creator>Yiting</dc:creator>
      <dc:date>2019-03-29T10:33:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547245#M33327</link>
      <description>&lt;P&gt;No problem!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm creating OldINVENTORY to hang on to the value of INVENTORY from the previous record. AscendingFlag is first set to 1, which is the "regularity" condition (all of the INVENTORY values are ascending within REGION and PRODUCT). Then, if an INVENTORY value is greater than the one in the record before, I set AscendingFlag to 0 (there is at least one case of the exception).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I restrict which variables appear in Inter01 with the "keep" statement. If you comment it out, you'll see the working values as they change, which might make things a little clearer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Tom&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 15:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547245#M33327</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-03-29T15:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547619#M33338</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot. I probably have not expressed myself right... In your output, from line 3 to 4 and from line 4 to 5, Inventory is increasing, but AsendingFlag did not identify them as 1... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2019 13:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547619#M33338</guid>
      <dc:creator>Yiting</dc:creator>
      <dc:date>2019-04-01T13:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to compare values within an ID</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547653#M33339</link>
      <description>&lt;P&gt;It's important to note that Inter01 only has one line for the entire region/product grouping, indicating if ANY of the transitions between the previous and the current record wasn't ascending.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a little different version of the program. It writes a line to Inter02 for every record, so you can see how AscendingFlag is set. It's important to note that it's a toggle; as soon as it gets set to zero, it stays that way for the rest of the grouping.&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;proc sort data=sashelp.shoes out=work.Have(keep=REGION PRODUCT INVENTORY);
	by REGION PRODUCT;
run;

data Inter01 Inter02;
	retain OldINVENTORY AscendingFlag;
	set Have;
	by REGION PRODUCT;

	if first.PRODUCT then
		do;
			OldINVENTORY=.;
			AscendingFlag=1;
		end;

	if INVENTORY &amp;gt; OldINVENTORY then;
	else AscendingFlag=0;
	OldINVENTORY=INVENTORY;

	if last.PRODUCT then
		output Inter01;
	output Inter02;
run;

proc sql;
	create table Want as select h.*, f.AscendingFlag from Have h inner join 
		Inter01 f on(h.REGION=f.REGION and h.PRODUCT=f.PRODUCT);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Apr 2019 16:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-compare-values-within-an-ID/m-p/547653#M33339</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-04-01T16:35:35Z</dc:date>
    </item>
  </channel>
</rss>

