<?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: Help creating a query to loop thorugh data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740707#M231424</link>
    <description>&lt;P&gt;I don't have enough information, so please check.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, isn't the waiting period from 1/1 to 1/10 9 days?&lt;BR /&gt;If we treat this as 10 days, then from 1/25 (NextElegibilityDate with client=1, ordernumber =4) to 2/4, the waiting time will be 11 days.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Then, the orderDate of ordernumber =3 and ordernumber =4 in client=1 is the same day, does it mean that the second one is treated as elegible for the same order date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in client=1, ordernumber =4, the elegible is determined first, not as a result of comparing NextElegibilityDate(2/4) and orderDate(1/25), is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 12 May 2021 03:16:28 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-05-12T03:16:28Z</dc:date>
    <item>
      <title>Help creating a query to loop thorugh data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740663#M231410</link>
      <description>&lt;P&gt;Have the following logic I would like to code.&lt;/P&gt;&lt;P&gt;After a client places an order, it has to wait&amp;nbsp;a ceirtan number of days before they are elegible to place a second order. I need to look at each transaction and determine if the order is elegible or not (if enough days have passed).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example: if the client places and order in Jan 1st, and the days to wait are 10, the next elegible order will be on Jan10.&lt;/P&gt;&lt;P&gt;there can be transactions in between, but they wont be elegible.&lt;/P&gt;&lt;P&gt;The first transaction for the client should always be marked as elegible.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so the data I have in the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; client ordernumber daysTowait orderDate :&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mydate &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 10 01/01/2021&lt;/P&gt;&lt;P&gt;1 2 10 03/01/2021&lt;/P&gt;&lt;P&gt;1 3 10 25/01/2021&lt;/P&gt;&lt;P&gt;1 4 10 25/01/2021&lt;/P&gt;&lt;P&gt;2 1 10 01/02/2021&lt;/P&gt;&lt;P&gt;2 2 10 03/02/2021&lt;/P&gt;&lt;P&gt;2 3 10 05/02/2021&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;I would lke to write a query that returns the following based on the data I have&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; client ordernumber daysTowait orderDate :&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; NextElegibilityDate :&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; isElegible $ ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; mydate &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;ddmmyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 1 10 01/01/2021 01/01/2021 Yes&lt;/P&gt;&lt;P&gt;1 2 10 03/01/2021 10/01/2021 No&lt;/P&gt;&lt;P&gt;1 3 10 25/01/2021 10/01/2021 Yes&lt;/P&gt;&lt;P&gt;1 4 10 25/01/2021 04/02/2021 Yes&lt;/P&gt;&lt;P&gt;2 1 10 01/02/2021 01/02/2021 Yes&lt;/P&gt;&lt;P&gt;2 2 10 03/02/2021 10/02/2021 No&lt;/P&gt;&lt;P&gt;2 3 10 05/02/2021 10/02/2021 No&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 00:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740663#M231410</guid>
      <dc:creator>spastranas</dc:creator>
      <dc:date>2021-05-12T00:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating a query to loop thorugh data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740705#M231422</link>
      <description>&lt;P&gt;1. Please use dedicated icon to paste code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. This is one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
  by CLIENT ORDERDATE;
  format NEXTELEGIBILITYDATE date9. ;
  if first.CLIENT then do;
    NEXTELEGIBILITYDATE=ORDERDATE+DAYSTOWAIT;
    ISELIGIBLE='Y';
  end;
  else if ORDERDATE=_LAG_DTE then do;
    ISELIGIBLE=_LAG_FLG;
  end;
  else if NEXTELEGIBILITYDATE&amp;lt;=ORDERDATE then do;
    NEXTELEGIBILITYDATE=ORDERDATE+DAYSTOWAIT;
    ISELIGIBLE='Y';
  end;
  else ISELIGIBLE='N';
  _LAG_DTE=ORDERDATE;
  _LAG_FLG=ISELIGIBLE;
  retain NEXTELEGIBILITYDATE _:;
  drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;CLIENT&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ORDERNUMBER&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;DAYSTOWAIT&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;ORDERDATE&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;NEXTELEGIBILITYDATE&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;ISELIGIBLE&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;01/01/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;11JAN2021&lt;/TD&gt;
&lt;TD class="l data"&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;03/01/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;11JAN2021&lt;/TD&gt;
&lt;TD class="l data"&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;25/01/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;04FEB2021&lt;/TD&gt;
&lt;TD class="l data"&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;4&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;25/01/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;04FEB2021&lt;/TD&gt;
&lt;TD class="l data"&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;01/02/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;11FEB2021&lt;/TD&gt;
&lt;TD class="l data"&gt;Y&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;03/02/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;11FEB2021&lt;/TD&gt;
&lt;TD class="l data"&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="r data"&gt;10&lt;/TD&gt;
&lt;TD class="r data"&gt;05/02/2021&lt;/TD&gt;
&lt;TD class="r data"&gt;11FEB2021&lt;/TD&gt;
&lt;TD class="l data"&gt;N&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&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>Wed, 12 May 2021 03:05:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740705#M231422</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-05-12T03:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating a query to loop thorugh data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740707#M231424</link>
      <description>&lt;P&gt;I don't have enough information, so please check.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, isn't the waiting period from 1/1 to 1/10 9 days?&lt;BR /&gt;If we treat this as 10 days, then from 1/25 (NextElegibilityDate with client=1, ordernumber =4) to 2/4, the waiting time will be 11 days.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Then, the orderDate of ordernumber =3 and ordernumber =4 in client=1 is the same day, does it mean that the second one is treated as elegible for the same order date?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, in client=1, ordernumber =4, the elegible is determined first, not as a result of comparing NextElegibilityDate(2/4) and orderDate(1/25), is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 03:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740707#M231424</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-05-12T03:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating a query to loop thorugh data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740709#M231426</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;
input client ordernumber daysTowait orderDate :ddmmyy10.;
format orderDate ddmmyy10.;
datalines;
1 1 10 01/01/2021
1 2 10 03/01/2021
1 3 10 25/01/2021
1 4 10 25/01/2021
2 1 10 01/02/2021
2 2 10 03/02/2021
2 3 10 05/02/2021
;
run;

data want;
	set have;
	by client;
	format NextElegibilityDate ddmmyy10.;
	NextElegibilityDate =orderDate + 10;
	diff =ifn(first.client,11, dif(orderDate));
	isElegible=ifc(diff&amp;gt;=10,'Y','N');
	drop diff;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 May 2021 03:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740709#M231426</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2021-05-12T03:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help creating a query to loop thorugh data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740711#M231427</link>
      <description>&lt;P&gt;If we follow the data presented now, we can achieve this with the following code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=next;
  by client orderDate ordernumber;
run;

data want;
  set next;
  by client orderDate ordernumber;
  length NextElegibilityDate 8 isElegible $3;
  format NextElegibilityDate ddmmyy10.;
  retain nextdt;
  if first.client then do;
    isElegible='Yes';
    NextElegibilityDate=orderDate;
    nextdt=orderDate+daysTowait;
  end; else
  do;
    NextElegibilityDate=nextdt;
    if not(first.orderDate) then do;
      isElegible='Yes';
      if last.orderDate then do;
        nextdt=orderDate+daysTowait;
        NextElegibilityDate=nextdt;
      end;
    end; else
    if orderDate&amp;gt;NextElegibilityDate then do;
      isElegible='Yes';
    end; else
    do;
      isElegible='No';
    end;
  end;
  drop nextdt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The point about daysTowait is excluded.&lt;/P&gt;</description>
      <pubDate>Wed, 12 May 2021 03:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-creating-a-query-to-loop-thorugh-data/m-p/740711#M231427</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-05-12T03:47:37Z</dc:date>
    </item>
  </channel>
</rss>

