<?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: Extracting the Count based on Conditions how to do it with proc sql in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284675#M59343</link>
    <description>&lt;P&gt;I have to assume that your SQL knowledge exceeds mine, or you wouldn't be asking.&amp;nbsp; So I can give you some pieces of the solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within your SELECT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by custid&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count(*) where ( (max(trndt) - trndt) &amp;lt;= 60 * 60 * 24 )&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2016 20:42:05 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-07-14T20:42:05Z</dc:date>
    <item>
      <title>Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284641#M59340</link>
      <description>&lt;P&gt;/* Variable 'S' will give us counts of transaction which happend in last 24 Hrs. from their last purchase*/&lt;BR /&gt;/*But how can I get same out with proc sql ??*/&lt;/P&gt;&lt;P&gt;options datestyle =mdy;&lt;BR /&gt;data ds1;&lt;BR /&gt;input trndt anydtdtm. trnid custid $;&lt;BR /&gt;format trndt datetime18.;&lt;BR /&gt;datalines;&lt;BR /&gt;7/12/2016 04:00:00 005 a&lt;BR /&gt;7/11/2016 01:00:00 004 a&lt;BR /&gt;7/12/2016 01:00:00 003 a&lt;BR /&gt;5/11/2016 04:00:00 004 b&lt;BR /&gt;5/12/2016 05:00:00 003 b&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sort data = ds1;&lt;BR /&gt;by custid descending trndt ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data ds2 (keep=s keep=custid);&lt;BR /&gt;set ds1;&lt;BR /&gt;by custid;&lt;BR /&gt;format y datetime18.;&lt;BR /&gt;retain y s;&lt;BR /&gt;if first.custid then Y=trndt ;&lt;BR /&gt;else if y=y;&lt;BR /&gt;x=y-trndt; if x=0 then s=1;else if x &amp;lt;=24*60*60 then s+1;&lt;BR /&gt;if last.custid then output;&lt;/P&gt;&lt;P&gt;proc print data =ds2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 19:20:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284641#M59340</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2016-07-14T19:20:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284675#M59343</link>
      <description>&lt;P&gt;I have to assume that your SQL knowledge exceeds mine, or you wouldn't be asking.&amp;nbsp; So I can give you some pieces of the solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Within your SELECT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;group by custid&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count(*) where ( (max(trndt) - trndt) &amp;lt;= 60 * 60 * 24 )&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2016 20:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284675#M59343</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-14T20:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284712#M59349</link>
      <description>&lt;P&gt;You didn't post the output yet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options datestyle =mdy;
data ds1;
input trndt &amp;amp; anydtdtm. trnid custid $;
format trndt datetime18.;
datalines;
7/12/2016 04:00:00  005 a
7/11/2016 01:00:00  004 a
7/12/2016 01:00:00  003 a
5/11/2016 04:00:00  004 b
5/12/2016 05:00:00  003 b
;
run;

proc sql;
select *,(select count(*) as s from ds1 where custid=a.custid 
 and trndt between intnx('dtday',a.trndt,-1,'s') and a.trndt) as s
 from ds1 as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Jul 2016 01:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284712#M59349</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-15T01:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284844#M59365</link>
      <description>&lt;P&gt;I want output like this :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS Output&lt;/P&gt;&lt;DIV class="branch"&gt;&lt;DIV&gt;&lt;DIV align="center"&gt;Obs custid s 1 2 &lt;TABLE cellspacing="0" cellpadding="5"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 15 Jul 2016 14:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284844#M59365</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2016-07-15T14:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284991#M59373</link>
      <description>&lt;PRE&gt;
So you want the max value of trndt for each custid ?


options datestyle =mdy;
data ds1;
input trndt &amp;amp; anydtdtm. trnid custid $;
format trndt datetime18.;
datalines;
7/12/2016 04:00:00  005 a
7/11/2016 01:00:00  004 a
7/12/2016 01:00:00  003 a
5/11/2016 04:00:00  004 b
5/12/2016 05:00:00  003 b
;
run;

proc sql;
select *,(select count(*) as s from ds1 where custid=a.custid 
 and trndt between intnx('dtday',a.trndt,-1,'s') and a.trndt) as s
 from (select * from ds1 group by custid having trndt=max(trndt)) as a;
quit;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jul 2016 03:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284991#M59373</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-16T03:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting the Count based on Conditions how to do it with proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284998#M59375</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;SPAN&gt;Xia Keshan !!!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-SPOILER&gt;&amp;nbsp;&lt;/LI-SPOILER&gt;</description>
      <pubDate>Sat, 16 Jul 2016 06:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-the-Count-based-on-Conditions-how-to-do-it-with-proc/m-p/284998#M59375</guid>
      <dc:creator>atul_desh</dc:creator>
      <dc:date>2016-07-16T06:17:39Z</dc:date>
    </item>
  </channel>
</rss>

