<?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: Logic to find who all are the customers who only uses gold card? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314466#M68494</link>
    <description>&lt;P&gt;i didn't understand the logic. could u please explain. i am not the getting it.&lt;/P&gt;</description>
    <pubDate>Sat, 26 Nov 2016 15:55:41 GMT</pubDate>
    <dc:creator>ROHINISDAS</dc:creator>
    <dc:date>2016-11-26T15:55:41Z</dc:date>
    <item>
      <title>Logic to find who all are the customers who only uses gold card?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314316#M68434</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below mentioned is the data from which i want to find the customer details who only uses gold card. I found the customers who uses whole three cards by using first. and last. concept. Now i am not able to put the logic how to find the &amp;nbsp;&lt;/P&gt;&lt;P&gt;1)customers who only uses gold card.&lt;/P&gt;&lt;P&gt;2) customers who uses platinum but not gold&amp;nbsp;&lt;/P&gt;&lt;P&gt;3)customers who uses titanium but not gold&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me out in solving the questions?&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/6017iAABAB2AA6E4D363C/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="secondquestion.JPG" title="secondquestion.JPG" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 14:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314316#M68434</guid>
      <dc:creator>ROHINISDAS</dc:creator>
      <dc:date>2016-11-25T14:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to find who all are the customers who only uses gold card?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314318#M68435</link>
      <description>&lt;P&gt;If using a 2XDOW, you will be able to have it done in Data step, however, SQL is just much simpler:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

/*1)customers who only uses gold card.
*/
proc sql;
select * from have
group by customer
having sum(x ne 'gold') =0;
quit;


/*2) customers who uses platinum but not gold 
*/

proc sql;
select * from have
group by customer
having sum(x eq 'Plat') &amp;gt;0 and sum(x eq 'gold') =0;
quit;

/*3)customers who uses titanium but not gold
*/
proc sql;
select * from have
group by customer
having sum(x eq 'tita') &amp;gt;0 and sum(x eq 'gold') =0;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Nov 2016 15:02:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314318#M68435</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-11-25T15:02:46Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to find who all are the customers who only uses gold card?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314335#M68440</link>
      <description>&lt;P&gt;Simpler yes, but not by much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The suggested SQL aproach requires 3 separate passes through the data, while the single DOW (don't need double DOW if the OP really meant it when he said he wanted "customer details" rather than customer transactions), requires only one pass, as per this program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, like virutally all cases where incoming records are already ordered by criteria pertinent to the problem, it will be faster than SQL - especially for large data sets.&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;data gold_only (keep=customer ntrans)
     plat_nogold (keep=customer ntrans ng np)
     tita_nogold (keep=customer ntrans ng nt);

  ng=0; np=0; nt=0;

  do ntrans=1 by 1 until (last.customer);
    set have;
    by customer;
    select (x);
      when ('gold') ng=ng+1;
      when ('plat') np=np+1;
      when ('tita') nt=nt+1;
    end;
  end;
  if ng=ntrans then output gold_only; else
  if ng=0 and np&amp;gt;0 then output plat_nogold; else
  if ng=0 and nt&amp;gt;0 then output tita_nogold;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if the OP does want customer &lt;STRONG&gt;transactions&lt;/STRONG&gt; based on the specified customer classification, then I would argue this double dow is not paticulary complicated, and teaches the user an important attribute about the likely advantages&amp;nbsp;of sequential processing in sas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data gold_only     plat_nogold     tita_nogold ;

  ng=0; np=0; nt=0;
  do ntrans=1 by 1 until (last.customer);
    set have;
    by customer;
    select (x);
      when ('gold') ng=ng+1;
      when ('plat') np=np+1;
      when ('tita') nt=nt+1;
    end;
  end;
  /* re-read the same group of records*/
  do until last.customer;
    set have;
    by customer;
    if ng=ntrans     then output gold_only;   else
    if ng=0 and np&amp;gt;0 then output plat_nogold; else
    if ng=0 and nt&amp;gt;0 then output tita_nogold;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Nov 2016 16:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314335#M68440</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-25T16:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to find who all are the customers who only uses gold card?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314466#M68494</link>
      <description>&lt;P&gt;i didn't understand the logic. could u please explain. i am not the getting it.&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 15:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314466#M68494</guid>
      <dc:creator>ROHINISDAS</dc:creator>
      <dc:date>2016-11-26T15:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: Logic to find who all are the customers who only uses gold card?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314481#M68502</link>
      <description>&lt;P&gt;Whenever you see a structure like "do .... until (last.customer)" with a SET statement (or merge or update statement) inside the do group, it means you want to read all the records for a given customer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the do group in the first program and the first do group of the second program, the purpose is to count the number of times X='gold' (variable ng), x='Plat' (np) and x='tita'.&amp;nbsp;&amp;nbsp; The SELECT group in my program is a substitue for&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x='gold' then ng=ng+1; else &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x='plat' then np=np+1; else&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if x='tita' then nt=nt+1;&lt;/P&gt;
&lt;P&gt;But the first do group also has DO &lt;EM&gt;&lt;STRONG&gt;ntrans=1 by 1&lt;/STRONG&gt;&lt;/EM&gt; until (last.customer), which just means to initialize ntrans to a 1 and increment by 1 for every iteration of the loop.&amp;nbsp; At the end of the loop NTRANS will be total number of all types of transaction.&amp;nbsp; It can then be compared to NG to identify gold-only customers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the other IF ... then output ... should be self-evident.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;The first program outputs 1 record per customer, i.e. you only wanted the id by customer type.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the second program shows how to output all the &lt;EM&gt;&lt;STRONG&gt;transactions&lt;/STRONG&gt;&lt;/EM&gt; by customer type (not by transaction type).&amp;nbsp; Because it requires output of transcations, it means that customer's transaction records have to be re-read, and explicitly output.&amp;nbsp; Therefore there is a second "do until (last.customer)" group with an embedded SET statement, and also an embedded OUTPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The take-home point here is that whenever you see two SET statements reading a given data set, they form two independent streams of data,&amp;nbsp;neither SET picks up where the other left off.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;regards&lt;/P&gt;
&lt;P&gt;Mark&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Nov 2016 18:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Logic-to-find-who-all-are-the-customers-who-only-uses-gold-card/m-p/314481#M68502</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2016-11-26T18:52:38Z</dc:date>
    </item>
  </channel>
</rss>

