<?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 extract visit using date of incident? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-visit-using-date-of-incident/m-p/865483#M341792</link>
    <description>&lt;P&gt;The date of the first visit occuring at or after the date of stroke can be obtained as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id stroke (dateOfStrk visitDate) (:mmddyy.) visitNum;
format dateofStrk visitDate yymmdd10.;
datalines;
1    0               .          11/1/2022     1
1    0               .          12/1/2022     2
1    0               .          1/1/2023       3
2    1     12/25/2022  11/1/2022      1
2    1     12/25/2022  12/1/2022      2
2    1     12/25/2022  1/1/2023        3
3    1     11/13/2022  11/1/2022      1
3    1     11/13/2022  12/1/2022      2
3    1     11/13/2022  11/1/2023      3
;

proc sql;
/* create table want as */
select 
    a.*, b.strkVisit format=yymmdd10.
from 
    have as a left join
    (select id, min(visitDate) as strkVisit 
    from have where stroke and visitDate&amp;gt;=dateOfStrk 
    group by id) as b
    on a.id=b.id
    order by id, visitNum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1679417189191.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81829i666D2B53595EC471/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1679417189191.png" alt="PGStats_0-1679417189191.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 21 Mar 2023 16:46:53 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2023-03-21T16:46:53Z</dc:date>
    <item>
      <title>How to extract visit using date of incident?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-visit-using-date-of-incident/m-p/865473#M341788</link>
      <description>&lt;P&gt;I am trying to create a new variable called "stroke visit" using the information below.&amp;nbsp;I have the date of stroke and visit numbers available. The stroke visit would be closest to the date of stroke (preferably before the latest visit) e.g. for ID 2 the visitnum should be "3".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id stroke dateofstrk &amp;nbsp; visitdate &amp;nbsp; visitnum&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11/1/2022 &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12/1/2022 &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2023 &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 12/25/2022 &amp;nbsp;11/1/2022 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;12/25/2022 &amp;nbsp;12/1/2022 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;2 &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;12/25/2022 &amp;nbsp;1/1/2023 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; 11/13/2022 &amp;nbsp;11/1/2022 &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1&amp;nbsp;&amp;nbsp; &amp;nbsp; 11/13/2022 &amp;nbsp;12/1/2022 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;3 &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;11/13/2022 &amp;nbsp;11/1/2023 &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 15:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-visit-using-date-of-incident/m-p/865473#M341788</guid>
      <dc:creator>shrutisd0</dc:creator>
      <dc:date>2023-03-21T15:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract visit using date of incident?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-visit-using-date-of-incident/m-p/865483#M341792</link>
      <description>&lt;P&gt;The date of the first visit occuring at or after the date of stroke can be obtained as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id stroke (dateOfStrk visitDate) (:mmddyy.) visitNum;
format dateofStrk visitDate yymmdd10.;
datalines;
1    0               .          11/1/2022     1
1    0               .          12/1/2022     2
1    0               .          1/1/2023       3
2    1     12/25/2022  11/1/2022      1
2    1     12/25/2022  12/1/2022      2
2    1     12/25/2022  1/1/2023        3
3    1     11/13/2022  11/1/2022      1
3    1     11/13/2022  12/1/2022      2
3    1     11/13/2022  11/1/2023      3
;

proc sql;
/* create table want as */
select 
    a.*, b.strkVisit format=yymmdd10.
from 
    have as a left join
    (select id, min(visitDate) as strkVisit 
    from have where stroke and visitDate&amp;gt;=dateOfStrk 
    group by id) as b
    on a.id=b.id
    order by id, visitNum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1679417189191.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81829i666D2B53595EC471/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1679417189191.png" alt="PGStats_0-1679417189191.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2023 16:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-visit-using-date-of-incident/m-p/865483#M341792</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2023-03-21T16:46:53Z</dc:date>
    </item>
  </channel>
</rss>

