<?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 How to group userid, cardid with multiple transaction codes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949765#M371492</link>
    <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;&lt;BR /&gt;input USERID $4. CARDID :$10. TRANCODE $4.;&lt;BR /&gt;cards;&lt;BR /&gt;1234 1234567890 3503&lt;BR /&gt;1234 1234567890 2013&lt;BR /&gt;1234 1234567890 7113&lt;BR /&gt;5678 2345678901 2013&lt;BR /&gt;5678 2345678901 7113&lt;BR /&gt;8907 3456789012 3503&lt;BR /&gt;8907 3456789012 2013&lt;BR /&gt;7658 4567890123 7113&lt;BR /&gt;7658 4567890123 7114&lt;BR /&gt;4356 5678901234 3503&lt;BR /&gt;4356 5678901234 2013&lt;BR /&gt;4356 5678901234 7113&lt;BR /&gt;9874 6789012345 3503&lt;BR /&gt;9874 6789012345 7113&lt;BR /&gt;5437 7890123456 3503&lt;BR /&gt;5461 8901234567 7113&lt;BR /&gt;5462 9012345678 2013&lt;BR /&gt;2543 0123456789 2013&lt;BR /&gt;2543 0123456789 7113&lt;BR /&gt;2543 0123456789 3503&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have huge dataset and the above data is dummy to replicate that dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which has card userid, cardid and transaction code. I have the following conditions to filter the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I want to get the records that have all userid and cardids with the trancodes of '3503' along with '2013' and '7113'&lt;/P&gt;&lt;P&gt;2. I don't need to get any records associated with just ('3503' and '2013') or ('2013' and '7113') or ('3503' and '7113') or individual tran codes&lt;/P&gt;&lt;P&gt;3. I have to have '3503' first and along with that I need to have trancodes of&amp;nbsp;'2013' and '7113'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to see the output result like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;USERID CARDID TRANCODE&lt;/U&gt;&lt;/STRONG&gt;&lt;BR /&gt;1234 1234567890 3503&lt;BR /&gt;1234 1234567890 2013&lt;BR /&gt;1234 1234567890 7113&lt;BR /&gt;4356 5678901234 3503&lt;BR /&gt;4356 5678901234 2013&lt;BR /&gt;4356 5678901234 7113&lt;BR /&gt;2543 0123456789 2013&lt;BR /&gt;2543 0123456789 7113&lt;BR /&gt;2543 0123456789 3503&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code and wasn't successful&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE WANT AS 
SELECT * 
FROM HAVE
WHERE TRANCODE IN ('3503','2013','7113')
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please help me. Thanks in advance&lt;/P&gt;</description>
    <pubDate>Fri, 01 Nov 2024 22:56:32 GMT</pubDate>
    <dc:creator>buddha_d</dc:creator>
    <dc:date>2024-11-01T22:56:32Z</dc:date>
    <item>
      <title>How to group userid, cardid with multiple transaction codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949765#M371492</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;data have;&lt;BR /&gt;input USERID $4. CARDID :$10. TRANCODE $4.;&lt;BR /&gt;cards;&lt;BR /&gt;1234 1234567890 3503&lt;BR /&gt;1234 1234567890 2013&lt;BR /&gt;1234 1234567890 7113&lt;BR /&gt;5678 2345678901 2013&lt;BR /&gt;5678 2345678901 7113&lt;BR /&gt;8907 3456789012 3503&lt;BR /&gt;8907 3456789012 2013&lt;BR /&gt;7658 4567890123 7113&lt;BR /&gt;7658 4567890123 7114&lt;BR /&gt;4356 5678901234 3503&lt;BR /&gt;4356 5678901234 2013&lt;BR /&gt;4356 5678901234 7113&lt;BR /&gt;9874 6789012345 3503&lt;BR /&gt;9874 6789012345 7113&lt;BR /&gt;5437 7890123456 3503&lt;BR /&gt;5461 8901234567 7113&lt;BR /&gt;5462 9012345678 2013&lt;BR /&gt;2543 0123456789 2013&lt;BR /&gt;2543 0123456789 7113&lt;BR /&gt;2543 0123456789 3503&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have huge dataset and the above data is dummy to replicate that dataset.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset which has card userid, cardid and transaction code. I have the following conditions to filter the data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I want to get the records that have all userid and cardids with the trancodes of '3503' along with '2013' and '7113'&lt;/P&gt;&lt;P&gt;2. I don't need to get any records associated with just ('3503' and '2013') or ('2013' and '7113') or ('3503' and '7113') or individual tran codes&lt;/P&gt;&lt;P&gt;3. I have to have '3503' first and along with that I need to have trancodes of&amp;nbsp;'2013' and '7113'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to see the output result like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;USERID CARDID TRANCODE&lt;/U&gt;&lt;/STRONG&gt;&lt;BR /&gt;1234 1234567890 3503&lt;BR /&gt;1234 1234567890 2013&lt;BR /&gt;1234 1234567890 7113&lt;BR /&gt;4356 5678901234 3503&lt;BR /&gt;4356 5678901234 2013&lt;BR /&gt;4356 5678901234 7113&lt;BR /&gt;2543 0123456789 2013&lt;BR /&gt;2543 0123456789 7113&lt;BR /&gt;2543 0123456789 3503&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this code and wasn't successful&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC SQL;
CREATE TABLE WANT AS 
SELECT * 
FROM HAVE
WHERE TRANCODE IN ('3503','2013','7113')
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please help me. Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 01 Nov 2024 22:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949765#M371492</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2024-11-01T22:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to group userid, cardid with multiple transaction codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949770#M371493</link>
      <description>&lt;P&gt;If I understood what you mean.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input USERID $4. CARDID :$10. TRANCODE $4.;
cards;
1234 1234567890 3503
1234 1234567890 2013
1234 1234567890 7113
5678 2345678901 2013
5678 2345678901 7113
8907 3456789012 3503
8907 3456789012 2013
7658 4567890123 7113
7658 4567890123 7114
4356 5678901234 3503
4356 5678901234 2013
4356 5678901234 7113
9874 6789012345 3503
9874 6789012345 7113
5437 7890123456 3503
5461 8901234567 7113
5462 9012345678 2013
2543 0123456789 2013
2543 0123456789 7113
2543 0123456789 3503
;
run;
proc sql;
create table want as
select * from have
 group by USERID,CARDID
  having sum(TRANCODE='3503') and sum(TRANCODE='2013') and sum(TRANCODE='7113')
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Nov 2024 06:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949770#M371493</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-11-02T06:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to group userid, cardid with multiple transaction codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949771#M371494</link>
      <description>&lt;P&gt;You say you want "3503" to come first for a given group; userid "2543" does not meet that requirement.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Nov 2024 06:59:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949771#M371494</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-02T06:59:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to group userid, cardid with multiple transaction codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949772#M371495</link>
      <description>&lt;P&gt;Otherwise, this is how you solve such things with a double DO in a DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input USERID $4. CARDID :$10. TRANCODE $4.;
cards;
1234 1234567890 3503
1234 1234567890 2013
1234 1234567890 7113
5678 2345678901 2013
5678 2345678901 7113
8907 3456789012 3503
8907 3456789012 2013
7658 4567890123 7113
7658 4567890123 7114
4356 5678901234 3503
4356 5678901234 2013
4356 5678901234 7113
9874 6789012345 3503
9874 6789012345 7113
5437 7890123456 3503
5461 8901234567 7113
5462 9012345678 2013
2543 0123456789 2013
2543 0123456789 7113
2543 0123456789 3503
;

proc sort data=have;
by userid cardid;
run;

data want;
do until (last.cardid);
  set have (where=(trancode in ("3503","2013","7113")));
  by userid cardid;
  if first.cardid and trancode = "3503" then _3503 = 1;
  if trancode = "2013" then _2013 = 1;
  if trancode = "7113" then _7113 = 1;
end;
do until (last.cardid);
  set have (where=(trancode in ("3503","2013","7113")));
  by userid cardid;
  if _3503 and _2013 and _7113 then output;
end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Nov 2024 07:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949772#M371495</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-11-02T07:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to group userid, cardid with multiple transaction codes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949790#M371501</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408" target="_blank" rel="noopener"&gt;Ksharp &lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Nov 2024 01:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-userid-cardid-with-multiple-transaction-codes/m-p/949790#M371501</guid>
      <dc:creator>buddha_d</dc:creator>
      <dc:date>2024-11-03T01:32:24Z</dc:date>
    </item>
  </channel>
</rss>

