<?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 calulate different between first visit and las visit date in same IDin in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695345#M212178</link>
    <description>idnumber first_date last_date&lt;BR /&gt;00001 5534&lt;BR /&gt;00001 . . . . . 10342&lt;BR /&gt;00002 4567&lt;BR /&gt;00002&lt;BR /&gt;00002 . . . . . 7800&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Output&lt;BR /&gt;Idnumber first_date last_date followup_date&lt;BR /&gt;00001 5534 10342 4808&lt;BR /&gt;00001 5534 10342 4808&lt;BR /&gt;00002 4567 7890 3323&lt;BR /&gt;00002 4567 7890 3323&lt;BR /&gt;00002 4567 7890 3323</description>
    <pubDate>Thu, 29 Oct 2020 20:10:02 GMT</pubDate>
    <dc:creator>Bksong</dc:creator>
    <dc:date>2020-10-29T20:10:02Z</dc:date>
    <item>
      <title>How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695324#M212170</link>
      <description>how to calulate follow up years?&lt;BR /&gt;&lt;BR /&gt;ID First visit(SAS date). Last visit(SAS date)&lt;BR /&gt;Id firstvisit lastvisit&lt;BR /&gt;01 5543&lt;BR /&gt;&lt;BR /&gt;01 11234&lt;BR /&gt;&lt;BR /&gt;02 5436&lt;BR /&gt;&lt;BR /&gt;02 8895&lt;BR /&gt;Numbers are SAS date.&lt;BR /&gt;&lt;BR /&gt;How to clalulate lastvisit- firstvisit?&lt;BR /&gt;It's difficult to calculate between first visit and last visit since located in different row.&lt;BR /&gt;&lt;BR /&gt;How can make code correctly??&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;BK.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 29 Oct 2020 19:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695324#M212170</guid>
      <dc:creator>Bksong</dc:creator>
      <dc:date>2020-10-29T19:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695327#M212171</link>
      <description>5543 is first visit&lt;BR /&gt;11234 is last visit&lt;BR /&gt;5436 is first visit&lt;BR /&gt;8895 is last visit</description>
      <pubDate>Thu, 29 Oct 2020 19:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695327#M212171</guid>
      <dc:creator>Bksong</dc:creator>
      <dc:date>2020-10-29T19:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695331#M212172</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/354742"&gt;@Bksong&lt;/a&gt;&amp;nbsp; Since you mentioned first and last visit and that your visit dates are nicely sorted in ascending order within a given ID, all you need in my opinion is &lt;STRONG&gt;range&lt;/STRONG&gt; function either in SQL, Proc means/summary&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Id $ visit;
format visit date9.;
cards;
01 5543
01 11234
02 5436
02 8895
;

proc sql;
 create table want as 
 select id, range(visit) as diff
 from have
 group by id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 19:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695331#M212172</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-29T19:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695340#M212175</link>
      <description>If visit date located in different calumn, how to make code?</description>
      <pubDate>Thu, 29 Oct 2020 19:57:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695340#M212175</guid>
      <dc:creator>Bksong</dc:creator>
      <dc:date>2020-10-29T19:57:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695341#M212176</link>
      <description>&lt;P&gt;Can you please post your "input" sample just like I posted the sample data have; and your expected output? plz&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 19:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695341#M212176</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-29T19:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695345#M212178</link>
      <description>idnumber first_date last_date&lt;BR /&gt;00001 5534&lt;BR /&gt;00001 . . . . . 10342&lt;BR /&gt;00002 4567&lt;BR /&gt;00002&lt;BR /&gt;00002 . . . . . 7800&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Output&lt;BR /&gt;Idnumber first_date last_date followup_date&lt;BR /&gt;00001 5534 10342 4808&lt;BR /&gt;00001 5534 10342 4808&lt;BR /&gt;00002 4567 7890 3323&lt;BR /&gt;00002 4567 7890 3323&lt;BR /&gt;00002 4567 7890 3323</description>
      <pubDate>Thu, 29 Oct 2020 20:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695345#M212178</guid>
      <dc:creator>Bksong</dc:creator>
      <dc:date>2020-10-29T20:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695347#M212180</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input id $ first_date last_date;
cards;
00001 5534 .
00001 . 10342
00002 4567 .
00002 . .
00002 .  7800
;

data want;
 do _n_=1 by 1 until(last.id);
  update have(obs=0) have;
  by id;
 end;
 do _n_=1 to _n_;
  followup_date=last_date-first_date;
  output;
 end;
run;

proc print noobs;run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&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="l header" scope="col"&gt;id&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;first_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;last_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;followup_date&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;00001&lt;/TD&gt;
&lt;TD class="r data"&gt;5534&lt;/TD&gt;
&lt;TD class="r data"&gt;10342&lt;/TD&gt;
&lt;TD class="r data"&gt;4808&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;00001&lt;/TD&gt;
&lt;TD class="r data"&gt;5534&lt;/TD&gt;
&lt;TD class="r data"&gt;10342&lt;/TD&gt;
&lt;TD class="r data"&gt;4808&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;00002&lt;/TD&gt;
&lt;TD class="r data"&gt;4567&lt;/TD&gt;
&lt;TD class="r data"&gt;7800&lt;/TD&gt;
&lt;TD class="r data"&gt;3233&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;00002&lt;/TD&gt;
&lt;TD class="r data"&gt;4567&lt;/TD&gt;
&lt;TD class="r data"&gt;7800&lt;/TD&gt;
&lt;TD class="r data"&gt;3233&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;00002&lt;/TD&gt;
&lt;TD class="r data"&gt;4567&lt;/TD&gt;
&lt;TD class="r data"&gt;7800&lt;/TD&gt;
&lt;TD class="r data"&gt;3233&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;</description>
      <pubDate>Thu, 29 Oct 2020 20:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695347#M212180</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-29T20:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to calulate different between first visit and las visit date in same IDin</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695357#M212181</link>
      <description>Thank you so much.</description>
      <pubDate>Thu, 29 Oct 2020 20:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-calulate-different-between-first-visit-and-las-visit-date/m-p/695357#M212181</guid>
      <dc:creator>Bksong</dc:creator>
      <dc:date>2020-10-29T20:56:57Z</dc:date>
    </item>
  </channel>
</rss>

