<?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: Sorting and flaging transactions. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227500#M41005</link>
    <description>&lt;P&gt;The code below will do what PaigeMiller's code is doing, except this will give you the same value for Sort_tranx if the ID and Date are the same.&amp;nbsp; Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date;
format Date mmddyy10.;
informat Date mmddyy10.;
datalines;
34532 01/01/2015
34532 02/03/2015
34532 05/06/2015
34532 01/01/2015
36978 01/02/2015
21562 01/01/2015
21562 01/02/2015
21562 01/03/2015
21562 01/04/2015
21562 01/05/2015
;
run;

proc sort data=have;
	by ID Date;
run;

data want;
  set have;
	by ID Date;
Date_lag=lag(Date);
	If First.ID then Sort_tranx=1;
	Else If First.ID=0 AND Date=Date_lag then do;
		Sort_tranx=Sort_tranx; end;
	Else Sort_tranx+1;
Drop Date_lag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 28 Sep 2015 14:28:17 GMT</pubDate>
    <dc:creator>dcruik</dc:creator>
    <dc:date>2015-09-28T14:28:17Z</dc:date>
    <item>
      <title>Sorting and flaging transactions.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227473#M40997</link>
      <description>&lt;P&gt;Hi I am trying to prepare a transactional data. I have &amp;nbsp;Individuals and their transaction dates. I want to sort data primarly on Customer ID and &amp;nbsp;then tranaction date. Until there it is not a big challenge, but in addition to this i require to print a new variable that states oder of every transaction by number for every individual. The final data would look like the picture i attached bellow.&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;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/328i6A3425CF844FBFFD/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Stack_Ques.png" title="Stack_Ques.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 11:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227473#M40997</guid>
      <dc:creator>omerzeybek</dc:creator>
      <dc:date>2015-09-28T11:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting and flaging transactions.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227481#M41000</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=original_data out=sorted_data;
    by id date;
run;
data sorted_data;
    set sorted_data;
    by id;
    if first.id then sort_tranx=0;
    sort_tranx+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 13:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227481#M41000</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2015-09-28T13:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting and flaging transactions.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227500#M41005</link>
      <description>&lt;P&gt;The code below will do what PaigeMiller's code is doing, except this will give you the same value for Sort_tranx if the ID and Date are the same.&amp;nbsp; Hope this helps!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date;
format Date mmddyy10.;
informat Date mmddyy10.;
datalines;
34532 01/01/2015
34532 02/03/2015
34532 05/06/2015
34532 01/01/2015
36978 01/02/2015
21562 01/01/2015
21562 01/02/2015
21562 01/03/2015
21562 01/04/2015
21562 01/05/2015
;
run;

proc sort data=have;
	by ID Date;
run;

data want;
  set have;
	by ID Date;
Date_lag=lag(Date);
	If First.ID then Sort_tranx=1;
	Else If First.ID=0 AND Date=Date_lag then do;
		Sort_tranx=Sort_tranx; end;
	Else Sort_tranx+1;
Drop Date_lag;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Sep 2015 14:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-and-flaging-transactions/m-p/227500#M41005</guid>
      <dc:creator>dcruik</dc:creator>
      <dc:date>2015-09-28T14:28:17Z</dc:date>
    </item>
  </channel>
</rss>

