<?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: Find out 3rd transaction and it’s user ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886609#M350336</link>
    <description>&lt;P&gt;Please explain further. Please tell us the logic that makes these two transactions are the 3rd of something. I would imagine that most answers will not use SQL (despite your request) as this is sooooo much easier in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;145 ; 16.3 ; 05/02/2022 14:00:00
111 ; 84 ; 05/02/2022 14:15:00&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please (when you get a chance) provide the data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;)&lt;/P&gt;</description>
    <pubDate>Thu, 27 Jul 2023 09:42:55 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-07-27T09:42:55Z</dc:date>
    <item>
      <title>Find out 3rd transaction and it’s user ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886608#M350335</link>
      <description>Hi guys, any idea on how do I find the 3rd transaction using proc sql ?&lt;BR /&gt;&lt;BR /&gt;The data as below&lt;BR /&gt;User_id ; Spend ; Transaction_date&lt;BR /&gt;111 ; 100.5 ; 08/01/2022 11:13:00&lt;BR /&gt;111 ; 55 ; 10/01/2022 12:00:00&lt;BR /&gt;121 ; 35 ; 18/01/2022 12:00:00&lt;BR /&gt;145 ; 24 ; 26/01/2022 08:00:00&lt;BR /&gt;145 ; 89 ; 05/02/2022 11:00:00&lt;BR /&gt;145 ; 16.3 ; 05/02/2022 14:00:00&lt;BR /&gt;111 ; 84 ; 05/02/2022 14:15:00&lt;BR /&gt;111 ; 30 ; 13/02/2022 12:31:00&lt;BR /&gt;&lt;BR /&gt;Sry for the bad display of data, because i type it using my phone.&lt;BR /&gt;&lt;BR /&gt;My desired output ;&lt;BR /&gt;User_id ; Spend ; Transaction_date&lt;BR /&gt;145 ; 16.3 ; 05/02/2022 14:00:00&lt;BR /&gt;111 ; 84 ; 05/02/2022 14:15:00&lt;BR /&gt;</description>
      <pubDate>Thu, 27 Jul 2023 09:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886608#M350335</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-07-27T09:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find out 3rd transaction and it’s user ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886609#M350336</link>
      <description>&lt;P&gt;Please explain further. Please tell us the logic that makes these two transactions are the 3rd of something. I would imagine that most answers will not use SQL (despite your request) as this is sooooo much easier in a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;145 ; 16.3 ; 05/02/2022 14:00:00
111 ; 84 ; 05/02/2022 14:15:00&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, please (when you get a chance) provide the data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 09:42:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886609#M350336</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-27T09:42:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find out 3rd transaction and it’s user ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886638#M350349</link>
      <description>&lt;PRE&gt;PROC SQL;&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;CREATE TABLE&lt;/FONT&gt; TRANSACTION (USER_ID INT, SPEND NUM, TRANSACTION_DATE NUM FORMAT=DATETIME19.);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (111 , 100.5 ,"01Feb2022 11:13:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (111 , 55 ,"03Feb2022 12:00:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (121 , 35 ,"06Feb2022 12:00:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (145 , 24 ,"06Feb2022 08:00:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (145 , 89 ,"07Feb2022 11:00:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (145 , 16.3 ,"08Feb2022 14:00:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (111 , 84 ,"08Feb2022 14:15:00"DT);&lt;BR /&gt;&lt;FONT color="#0000FF"&gt;INSERT INTO&lt;/FONT&gt; TRANSACTION &lt;FONT color="#0000FF"&gt;VALUES&lt;/FONT&gt; (111 , 30 ,"13Feb2022 12:31:00"DT);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Based on the above sas code, you will get the following table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE class="table" aria-label="Data Set WORK.TRANSACTION"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col" width="73px" height="19px"&gt;USER_ID&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="86px" height="19px"&gt;SPEND&lt;/TH&gt;
&lt;TH class="r header" scope="col" width="182px" height="19px"&gt;TRANSACTION_DATE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;111&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;100.5&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;01FEB2022:11:13:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;111&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;55.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;03FEB2022:12:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;145&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;24.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;06FEB2022:08:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;121&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;35.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;06FEB2022:12:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;145&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;89.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;07FEB2022:11:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;145&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;16.3&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;08FEB2022:14:00:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;111&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;84.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;08FEB2022:14:15:00&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="73px" height="30px" class="r data"&gt;111&lt;/TD&gt;
&lt;TD width="86px" height="30px" class="r data"&gt;30.0&lt;/TD&gt;
&lt;TD width="182px" height="30px" class="r data"&gt;13FEB2022:12:31:00&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 modified the values to shows all transaction within the month of February 2023.&lt;/P&gt;
&lt;P&gt;and let me rephrase it as "find the 3rd transaction of the month".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;User_id &lt;FONT color="#FF6600"&gt;111&lt;/FONT&gt; made his/her 3rd transaction on&amp;nbsp;&lt;FONT color="#FF6600"&gt;08FEB2022:14:15:00&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;User_id &lt;FONT color="#FF6600"&gt;145&lt;/FONT&gt; made his/her 3rd transaction on&amp;nbsp;&lt;FONT color="#FF6600"&gt;08FEB2022:14:00:00&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Btw, please share with me on how to solve it by using both SQL and DATA step.&lt;/P&gt;
&lt;P&gt;Beside, I'm always using SQL because it's commonly used by many companies and I'm learning it to land my first job as data analyst.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your help is greatly appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 13:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886638#M350349</guid>
      <dc:creator>ChrisWoo</dc:creator>
      <dc:date>2023-07-27T13:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find out 3rd transaction and it’s user ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886641#M350352</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/442441"&gt;@ChrisWoo&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;User_id &lt;FONT color="#FF6600"&gt;111&lt;/FONT&gt; made his/her 3rd transaction on&amp;nbsp;&lt;FONT color="#FF6600"&gt;08FEB2022:14:15:00&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;User_id &lt;FONT color="#FF6600"&gt;145&lt;/FONT&gt; made his/her 3rd transaction on&amp;nbsp;&lt;FONT color="#FF6600"&gt;08FEB2022:14:00:00&lt;/FONT&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This information about 3rd within a user ID has not been previously stated. This clears up my confusion. Thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I will provide DATA step solutions, as I doubt seriously that SQL can do this easily, and so I will not provide SQL for this. See &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 14 — Use the right tool&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=transaction;
    by user_id transaction_date;
run;

data want;
    set transaction;
    by user_id;
    if first.user_id then count=0;
    count+1;
    if count=3 then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 14:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-3rd-transaction-and-it-s-user-ID/m-p/886641#M350352</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-07-27T14:03:40Z</dc:date>
    </item>
  </channel>
</rss>

