<?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: How to calculated row difference by group with 'from - to' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710596#M218772</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;

    ldate=lag(date);
    if var1="START" then dif=0;
    else dif=intck('day', ldate, date);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit : removed useless by name statement.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Jan 2021 16:09:47 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2021-01-11T16:09:47Z</dc:date>
    <item>
      <title>How to calculated row difference by group with 'from - to'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710593#M218770</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I would like to calculate difference between START - END for each name.&lt;/P&gt;
&lt;P&gt;Assuming: table is already sorted by name date,&lt;/P&gt;
&lt;P&gt;START is always first,&lt;/P&gt;
&lt;P&gt;has to be at least one START per name but always there is a sequence START END START..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table have like this:&lt;/P&gt;
&lt;PRE&gt;DATA HAVE;
LENGTH name $10. var1 $5.;
 INPUT name $ date :date9. var1 $;
 format date date9. ;
 DATALINES;
aaa 10JUN2020 START
aaa 15JUN2020 END
bbb 10JUL2020 START
bbb 20JUL2020 END
bbb 25JUL2020 START
bbb 01SEP2020 END
ccc 20JUN2020 START
ddd 15JUL2020 START
ddd 30JUL2020 END
ddd 02SEP2020 START
;
RUN;&lt;/PRE&gt;
&lt;P&gt;want like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="cactooos_0-1610380614425.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53384i51C68E1531E4A847/image-size/medium?v=v2&amp;amp;px=400" role="button" title="cactooos_0-1610380614425.png" alt="cactooos_0-1610380614425.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I know how to do it within the group but got lost with START END piece&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Huge thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710593#M218770</guid>
      <dc:creator>cactooos</dc:creator>
      <dc:date>2021-01-11T16:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculated row difference by group with 'from - to'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710596#M218772</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;

    ldate=lag(date);
    if var1="START" then dif=0;
    else dif=intck('day', ldate, date);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Edit : removed useless by name statement.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Jan 2021 16:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710596#M218772</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2021-01-11T16:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculated row difference by group with 'from - to'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710606#M218777</link>
      <description>Works perfectly, thanks!</description>
      <pubDate>Mon, 11 Jan 2021 16:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calculated-row-difference-by-group-with-from-to/m-p/710606#M218777</guid>
      <dc:creator>cactooos</dc:creator>
      <dc:date>2021-01-11T16:19:34Z</dc:date>
    </item>
  </channel>
</rss>

