<?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 Flip Flop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259085#M269003</link>
    <description>&lt;P&gt;&lt;BR /&gt;customer Pin&lt;BR /&gt;C1 P1&lt;BR /&gt;C1 P1&lt;/P&gt;&lt;P&gt;C2 P1&lt;BR /&gt;C2 P2&lt;BR /&gt;C2 p1&lt;/P&gt;&lt;P&gt;C3 P1&lt;BR /&gt;C3 P2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;C4 P1&lt;BR /&gt;C4 P2&lt;BR /&gt;C4 P1&lt;BR /&gt;C4 P3&lt;/P&gt;&lt;P&gt;Here the explanation for each customer scenario is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;C1--No Pin Change&amp;nbsp;&lt;BR /&gt;C2 --Flip Flop (originally P1,changed to P2 and got back to P1)&amp;nbsp;&lt;SPAN&gt;(Number of customers=1)&lt;/SPAN&gt;&lt;BR /&gt;C3 --Change in Pin&lt;BR /&gt;C4--FlipFlop, then Pin Change&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have dataset with 24.2 Million records with above scenarios. How to display following statitsitcs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Number of customers &amp;nbsp; &amp;nbsp; &amp;nbsp; Description&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;No Pin Change&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Flip Flop &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Change in Pin&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FlipFlop, then Pin Change&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2016 15:27:58 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2016-03-25T15:27:58Z</dc:date>
    <item>
      <title>Flip Flop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259085#M269003</link>
      <description>&lt;P&gt;&lt;BR /&gt;customer Pin&lt;BR /&gt;C1 P1&lt;BR /&gt;C1 P1&lt;/P&gt;&lt;P&gt;C2 P1&lt;BR /&gt;C2 P2&lt;BR /&gt;C2 p1&lt;/P&gt;&lt;P&gt;C3 P1&lt;BR /&gt;C3 P2&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;C4 P1&lt;BR /&gt;C4 P2&lt;BR /&gt;C4 P1&lt;BR /&gt;C4 P3&lt;/P&gt;&lt;P&gt;Here the explanation for each customer scenario is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;C1--No Pin Change&amp;nbsp;&lt;BR /&gt;C2 --Flip Flop (originally P1,changed to P2 and got back to P1)&amp;nbsp;&lt;SPAN&gt;(Number of customers=1)&lt;/SPAN&gt;&lt;BR /&gt;C3 --Change in Pin&lt;BR /&gt;C4--FlipFlop, then Pin Change&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have dataset with 24.2 Million records with above scenarios. How to display following statitsitcs:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Number of customers &amp;nbsp; &amp;nbsp; &amp;nbsp; Description&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;No Pin Change&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Flip Flop &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Change in Pin&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FlipFlop, then Pin Change&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 15:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259085#M269003</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2016-03-25T15:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flip Flop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259106#M269004</link>
      <description>&lt;P&gt;Here's one approach. Note that I added a few additional cases. I don't know if they are practical from your standpoint.&lt;/P&gt;
&lt;P&gt;If there are more than 4 possible pins then increase the size of the array P and add to the retain statement.&lt;/P&gt;
&lt;P&gt;BTW your example data result is incorrect. C2 has values of P1, P2 and p1. P1 is not equal to p1 in character terms, so would be a change not a flip flop. I manipulated the data to be as your example result though.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input customer $ pin $;
datalines;
C1 P1
C1 P1
C2 P1
C2 P2
C2 P1
C3 P1
C3 P2
C4 P1
C4 P2
C4 P1
C4 P3
C5 P1
C5 P2
C5 P1
C5 P3
C5 P2
C6 P1
C6 P2
C6 P3
C6 P4
;
run;
proc format library=work;
value mycode 
1 = "No change:"
2 = "Change"
3 = "Flip flop"
4 = "Flip flop with change"
;
run;

data table ;
   set have;
   by notsorted customer;
   length p1 - p4 $ 4;
   Array pins $ p1 - p4;
   retain code pincount p1 - p4;
   if first.customer then do;
   /* reset stuff*/
      call missing(of pins(*));
      code = 1;
      pins[1]=pin;
      pincount = 1;
   end;
   else do;
      pinposition = whichc(pin,of pins(*));
      if pinposition = 0 then do;
         /* new pin has been encountered*/
         pincount=pincount+1;
         if code ne 2 then code = code +1;
         pins[pincount]=pin;
      end;
      Else if pinposition &amp;lt; pincount then do;
         /* flip flop*/
         code = min(code+1,4);
      end;
   end;
   if last.customer then output;
   keep customer pin code;
run;

proc freq data=table;
   table code/nopercent nocum;
   format code mycode.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm sure there's some slick with DOW loops and such but this is relatively straightforward addressing the likely conditions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 18:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259106#M269004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-25T18:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Flip Flop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259114#M269005</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16600"&gt;@SASPhile﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's another approach, developed unaware of&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;'s code and assuming that sequences of identical pins, e.g. (P1), (P1, P1), (P1, P1, P1) can be regarded equivalent ("No Pin Change"). Similarly,&amp;nbsp;&lt;SPAN&gt;(P1, P2, P2, P1) would be classified as "Flip Flop," etc.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data have;
input customer $ pin :$12.;
cards;
C1 P1
C1 P1
C2 P1
C2 P2
C2 P1
C3 P1
C3 P2
C4 P1
C4 P2
C4 P1
C4 P3
;

%let n=62; /* max. number of different pins (should be &amp;lt;=62) */

/* Determine patterns */

data want;
do until(last.customer);
  set have;
  array pins[&amp;amp;n] $12; /* please adapt array size and length as appropriate */
  length pattern $&amp;amp;n; /* please set length equal to array size */
  by customer pin notsorted;
  if first.pin then do;
    if pin not in pins then do;
      i=sum(i,1);
      pins[i]=pin;
    end;
    w=whichc(pin, of pins[*]);
    pattern=cats(pattern, byte(64+w+(w&amp;gt;26)*6-(w&amp;gt;52)*75));
  end;
end;
drop i w pin:;
run;

/* Describe patterns */

proc format;
value $pattern (default=62) /* default length must be &amp;gt;= max. label length */
'A'    = 'No Pin Change'
'ABA'  = 'Flip Flop'
'AB'   = 'Change in Pin'
'ABAC' = 'Flip Flop, then Pin Change'
; /* Please add and name more patterns as you like, according to the pat- */
run; /* tern symbol sequence: A, B, C, ..., Z, a, ..., z, 0, 1, ..., 9.   */

/* Count customers by pattern */

proc freq data=want order=data noprint; /* (you may want to omit "order=data") */
format pattern $pattern.;
tables pattern / out=frq;
run;

proc print data=frq noobs label;
label count   = 'Number of customers'
      pattern = 'Description';
var count pattern;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 18:42:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259114#M269005</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-25T18:42:35Z</dc:date>
    </item>
    <item>
      <title>Re: Flip Flop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259202#M269006</link>
      <description>&lt;P&gt;If you care for a solution based on pattern matching :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $scenario
"FFPC" = "Flip Flop, then Pin Change"
"FF"   = "Flip Flop"
"PC"   = "Change in Pin"
"NPC"  = "No Pin Change";
run;

data want;
length prxTarget $2000 scenario $4;
if not prxFFPC then prxFFPC + prxParse("/(\([^)]+\))(\([^)]+\))+\1\([^)]+\)/");
if not prxFF   then prxFF   + prxParse("/(\([^)]+\))(\([^)]+\))+\1/");
if not prxPC   then prxPC   + prxParse("/(\([^)]+\)){2,}/");
do until(last.customer);
    set have; by customer pin notsorted;
    if first.pin then prxTarget = cats(prxTarget, "(", pin, ")");
    end;
select;
    when (prxMatch(prxFFPC, prxTarget)) scenario = "FFPC";
    when (prxMatch(prxFF,   prxTarget)) scenario = "FF";
    when (prxMatch(prxPC,   prxTarget)) scenario = "PC";
    otherwise                           scenario = "NPC";
    end;
format scenario $scenario.;
drop prx: pin;
run;

proc print data=want noobs; run;

proc freq data=want;
table scenario;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 26 Mar 2016 02:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flip-Flop/m-p/259202#M269006</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-26T02:44:48Z</dc:date>
    </item>
  </channel>
</rss>

