<?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: dates interruptions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629765#M186324</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296619"&gt;@Aljosa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;PATIENT	VISITDT	INTENSITY	DATE_ONSET	DATE_END	term2
1	31DEC2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31DEC2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31DEC2015	Grade 4	.	.	hyperuricemia
1	31DEC2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.janv.16	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.janv.16	Grade 1 (Mild)	.	.	increase AST
1	18.janv.16	Grade 3 (Severe)	.	.	hyperuricemia
1	18.janv.16	Grade 2 (Moderate)	.	.	hypokalemia
1	22.janv.16		.	.	lengthen about qtcf
1	22.janv.16	Grade 1 (Mild)	.	.	lowering blood calcium
1	15FEB2016	Grade 2 (Moderate)	.	.	athralgia
1	15FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18FEB2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23FEB2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23FEB2016	Grade 1 (Mild)	.	.	increase AST
1	23FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.mars.16	Grade 1 (Mild)	.	.	increase AST
1	23.mars.16		.	.	lengthen about qtcf
1	23.mars.16	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 1 (Mild)	.	.	hyperglycemia&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;In the table above you can see an example of patients reporting adverse events within different visits in hospitals. VISITDT is a visit date. term2 is adverse event verbatim. columns DATE_ONSET(=start date) and DATE_END are still not populated. I've chosen as example "hyperuricemia" to explain my problem. You can see that this patient #1 had hyperuricemia in all visits, except on the visit on 22.jan.2016.&lt;/P&gt;
&lt;P&gt;Thus, in my final table I would like to have only 2 rows for hyperuricemia (including max INTENSITY):&lt;/P&gt;
&lt;P&gt;1st row: term2=hyperuricemia DATE_ONSET=31.dec.2015 DATE_END=18.jan.2016 INTENSITY=Grade 4&lt;/P&gt;
&lt;P&gt;2nd row: term2=hyperuricemia DATE_ONSET=15.feb.2016 DATE_END=23.mar.2016 INTENSITY=Grade 3 (Severe)&lt;/P&gt;
&lt;P&gt;Basically I know how to have first and last date with proc sort, but my main problem is how to take into account the interruptions. Please could anyone help? I think program should look row by row, and if no hyperuricemia then it should take the previous VISITDT as end date. Then when program see hyperuricemia again it should take VISITDT as a new DATE_ONSET, and so on... THANK YOU!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dates interruptions.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36614iDF19CFC14C6F981C/image-size/large?v=v2&amp;amp;px=999" role="button" title="dates interruptions.jpg" alt="dates interruptions.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please supply example data in a WORKING DATA STEP WITH DATALINES, as you have been shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;in &lt;A href="https://communities.sas.com/t5/SAS-Programming/continuous-date/m-p/601899" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/continuous-date/m-p/601899&lt;/A&gt;. Right now, your dates can not be imported with a default SAS informat.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Mar 2020 10:39:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-05T10:39:07Z</dc:date>
    <item>
      <title>dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629752#M186316</link>
      <description>&lt;PRE&gt;PATIENT	VISITDT	INTENSITY	DATE_ONSET	DATE_END	term2
1	31DEC2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31DEC2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31DEC2015	Grade 4	.	.	hyperuricemia
1	31DEC2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.janv.16	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.janv.16	Grade 1 (Mild)	.	.	increase AST
1	18.janv.16	Grade 3 (Severe)	.	.	hyperuricemia
1	18.janv.16	Grade 2 (Moderate)	.	.	hypokalemia
1	22.janv.16		.	.	lengthen about qtcf
1	22.janv.16	Grade 1 (Mild)	.	.	lowering blood calcium
1	15FEB2016	Grade 2 (Moderate)	.	.	athralgia
1	15FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18FEB2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23FEB2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23FEB2016	Grade 1 (Mild)	.	.	increase AST
1	23FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.mars.16	Grade 1 (Mild)	.	.	increase AST
1	23.mars.16		.	.	lengthen about qtcf
1	23.mars.16	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 1 (Mild)	.	.	hyperglycemia&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;In the table above you can see an example of patients reporting adverse events within different visits in hospitals. VISITDT is a visit date. term2 is adverse event verbatim. columns DATE_ONSET(=start date) and DATE_END are still not populated. I've chosen as example "hyperuricemia" to explain my problem. You can see that this patient #1 had hyperuricemia in all visits, except on the visit on 22.jan.2016.&lt;/P&gt;&lt;P&gt;Thus, in my final table I would like to have only 2 rows for hyperuricemia (including max INTENSITY):&lt;/P&gt;&lt;P&gt;1st row: term2=hyperuricemia DATE_ONSET=31.dec.2015 DATE_END=18.jan.2016 INTENSITY=Grade 4&lt;/P&gt;&lt;P&gt;2nd row: term2=hyperuricemia DATE_ONSET=15.feb.2016 DATE_END=23.mar.2016 INTENSITY=Grade 3 (Severe)&lt;/P&gt;&lt;P&gt;Basically I know how to have first and last date with proc sort, but my main problem is how to take into account the interruptions. Please could anyone help? I think program should look row by row, and if no hyperuricemia then it should take the previous VISITDT as end date. Then when program see hyperuricemia again it should take VISITDT as a new DATE_ONSET, and so on... THANK YOU!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dates interruptions.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36614iDF19CFC14C6F981C/image-size/large?v=v2&amp;amp;px=999" role="button" title="dates interruptions.jpg" alt="dates interruptions.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 10:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629752#M186316</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-05T10:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629765#M186324</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/296619"&gt;@Aljosa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;PATIENT	VISITDT	INTENSITY	DATE_ONSET	DATE_END	term2
1	31DEC2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31DEC2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31DEC2015	Grade 4	.	.	hyperuricemia
1	31DEC2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.janv.16	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.janv.16	Grade 1 (Mild)	.	.	increase AST
1	18.janv.16	Grade 3 (Severe)	.	.	hyperuricemia
1	18.janv.16	Grade 2 (Moderate)	.	.	hypokalemia
1	22.janv.16		.	.	lengthen about qtcf
1	22.janv.16	Grade 1 (Mild)	.	.	lowering blood calcium
1	15FEB2016	Grade 2 (Moderate)	.	.	athralgia
1	15FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18FEB2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23FEB2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23FEB2016	Grade 1 (Mild)	.	.	increase AST
1	23FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.mars.16	Grade 1 (Mild)	.	.	increase AST
1	23.mars.16		.	.	lengthen about qtcf
1	23.mars.16	Grade 3 (Severe)	.	.	hyperuricemia
1	23.mars.16	Grade 1 (Mild)	.	.	hyperglycemia&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;In the table above you can see an example of patients reporting adverse events within different visits in hospitals. VISITDT is a visit date. term2 is adverse event verbatim. columns DATE_ONSET(=start date) and DATE_END are still not populated. I've chosen as example "hyperuricemia" to explain my problem. You can see that this patient #1 had hyperuricemia in all visits, except on the visit on 22.jan.2016.&lt;/P&gt;
&lt;P&gt;Thus, in my final table I would like to have only 2 rows for hyperuricemia (including max INTENSITY):&lt;/P&gt;
&lt;P&gt;1st row: term2=hyperuricemia DATE_ONSET=31.dec.2015 DATE_END=18.jan.2016 INTENSITY=Grade 4&lt;/P&gt;
&lt;P&gt;2nd row: term2=hyperuricemia DATE_ONSET=15.feb.2016 DATE_END=23.mar.2016 INTENSITY=Grade 3 (Severe)&lt;/P&gt;
&lt;P&gt;Basically I know how to have first and last date with proc sort, but my main problem is how to take into account the interruptions. Please could anyone help? I think program should look row by row, and if no hyperuricemia then it should take the previous VISITDT as end date. Then when program see hyperuricemia again it should take VISITDT as a new DATE_ONSET, and so on... THANK YOU!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dates interruptions.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36614iDF19CFC14C6F981C/image-size/large?v=v2&amp;amp;px=999" role="button" title="dates interruptions.jpg" alt="dates interruptions.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please supply example data in a WORKING DATA STEP WITH DATALINES, as you have been shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;in &lt;A href="https://communities.sas.com/t5/SAS-Programming/continuous-date/m-p/601899" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/continuous-date/m-p/601899&lt;/A&gt;. Right now, your dates can not be imported with a default SAS informat.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 10:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629765#M186324</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-05T10:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629790#M186340</link>
      <description>&lt;P&gt;How to do it? I copy my spreadsheet here in text? It doesnt work. I dont remember how I did it last time. Thank you.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 13:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629790#M186340</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-05T13:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629792#M186342</link>
      <description>&lt;P&gt;Follow the link I posted previously; there you see a working data step with dates and even strings that contain blanks.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 13:38:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629792#M186342</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-05T13:38:20Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629818#M186356</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1	31DEC2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31DEC2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31DEC2015	Grade 4	.	.	hyperuricemia
1	31DEC2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.01.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.01.2016	Grade 1 (Mild)	.	.	increase AST
1	18.01.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.01.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	22.01.2016		.	.	lengthen about qtcf
1	22.01.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	15FEB2016	Grade 2 (Moderate)	.	.	athralgia
1	15FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18FEB2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18FEB2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23FEB2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23FEB2016	Grade 1 (Mild)	.	.	increase AST
1	23FEB2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.03.2016	Grade 1 (Mild)	.	.	increase AST
1	23.03.2016		.	.	lengthen about qtcf
1	23.03.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 1 (Mild)	.	.	hyperglycemia&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Like this? Here you have dates and blanks...&lt;/P&gt;&lt;P&gt;I used "insert SAS code" tool&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 14:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629818#M186356</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-05T14:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629829#M186364</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile cards expandtabs truncover;
  input patient	$100.	visitdt (:ddmmyy10.) INTENSITY $100. (date_onset date_end) (:ddmmyy10.) term2 $100.;
  format visitdt date_onset	date_end ddmmyy10.;
datalines;
1	31.12.2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31.12.2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31.12.2015	Grade 4	.	.	hyperuricemia
1	31.12.2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.01.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.01.2016	Grade 1 (Mild)	.	.	increase AST
1	18.01.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.01.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	22.01.2016		.	.	lengthen about qtcf
1	22.01.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	15.02.2016	Grade 2 (Moderate)	.	.	athralgia
1	15.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.02.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18.02.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18.02.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23.02.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23.02.2016	Grade 1 (Mild)	.	.	increase AST
1	23.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.03.2016	Grade 1 (Mild)	.	.	increase AST
1	23.03.2016		.	.	lengthen about qtcf
1	23.03.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 1 (Mild)	.	.	hyperglycemia

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Like this?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 14:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629829#M186364</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-05T14:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629843#M186373</link>
      <description>&lt;P&gt;Almost:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='09'x dsd truncover;
input patient :$10. visitdt :ddmmyy10. INTENSITY :$20. (date_onset date_end) (:ddmmyy10.) term2 :$30.;
format visitdt date_onset date_end ddmmyy10.;
datalines;
1	31.12.2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31.12.2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31.12.2015	Grade 4	.	.	hyperuricemia
1	31.12.2015	Grade 1 (Mild)	.	.	hypokalemia
1	18.01.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.01.2016	Grade 1 (Mild)	.	.	increase AST
1	18.01.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.01.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	22.01.2016		.	.	lengthen about qtcf
1	22.01.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	15.02.2016	Grade 2 (Moderate)	.	.	athralgia
1	15.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.02.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18.02.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	18.02.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	23.02.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23.02.2016	Grade 1 (Mild)	.	.	increase AST
1	23.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	23.03.2016	Grade 1 (Mild)	.	.	increase AST
1	23.03.2016		.	.	lengthen about qtcf
1	23.03.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 1 (Mild)	.	.	hyperglycemia
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since your text block contains tabs as separators(delimiters), we can use those. The dsd option lets SAS recognize a missing character value, so we now get a nice dataset. Note that a datalines block ends with a line with a single semicolon; this semicolon must immediately follow the final dataline, otherwise you get one or more empty observation(s). Since the datalines block ends the data step per definition, no run; statement is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let searchterm=hyperuricemia;
options mergenoby=nowarn;

data want;
set have (drop=date_onset date_end);
by patient visitdt;
retain date_onset date_end max_grade term_found;
format date_onset date_end ddmmyy10. max_grade $20.;
if first.patient then do;
  date_onset = .;
  date_end = .;
  max_grade = '';
end;
if first.visitdt then term_found = 0;
if term2 = "&amp;amp;searchterm" then do;
  if date_onset = . then date_onset = visitdt;
  term_found = 1;
  if intensity &amp;gt; max_grade then max_grade = intensity;
end;
if last.visitdt and date_onset ne . then do;
  if term_found then date_end = visitdt;
  else do;
    output;
    date_end = visitdt;
    date_onset = .;
    max_grade = '';
  end;
end;
if last.patient and date_onset ne . then do;
  date_end = visitdt;
  output;
end;
keep patient date_onset date_end max_grade;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 15:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/629843#M186373</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-05T15:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630013#M186458</link>
      <description>&lt;P&gt;Hello Kurt,&lt;/P&gt;&lt;P&gt;It doesnt work, as I get the table without adverse events.&lt;/P&gt;&lt;P&gt;I would need a table summarizing, per patient, each adverse event with its start and end date, taking into account interruptions (example for hyperuricemia, the event was interrupted on 22.jan.2016).&lt;/P&gt;&lt;P&gt;Kind regards.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 07:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630013#M186458</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-06T07:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630015#M186460</link>
      <description>&lt;P&gt;I tested my code. It creates&amp;nbsp;&lt;EM&gt;exactly&lt;/EM&gt;&amp;nbsp;the two rows you mentioned in your initial post.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 08:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630015#M186460</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-06T08:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630087#M186479</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;when I run the table "have" I get this (so, I have a problem somewhere):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table have.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36636i771936AC89DF5B32/image-size/large?v=v2&amp;amp;px=999" role="button" title="table have.png" alt="table have.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If however I run your main program directly on my original table with all patients, I get this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table want.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36637iF5D47072917B136B/image-size/large?v=v2&amp;amp;px=999" role="button" title="table want.png" alt="table want.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(Note that in your main program I added only "term2" in instruction keep at the end)&lt;/P&gt;&lt;P&gt;So, I see only 4 rows for patient number 1, and no hyperuricemia there...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the program below I put all events for the patient number 1:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='09'x dsd truncover;
input patient :$10. visitdt :ddmmyy10. INTENSITY :$20. (date_onset date_end) (:ddmmyy10.) term2 :$30.;
format visitdt date_onset date_end ddmmyy10.;
datalines;
1	31.12.2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31.12.2015	Grade 1 (Mild)	.	.	hypokalemia
1	31.12.2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31.12.2015	Grade 4	.	.	hyperuricemia
1	18.01.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.01.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.01.2016	Grade 1 (Mild)	.	.	increase AST
1	18.01.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	22.01.2016		.	.	lengthen about qtcf
1	22.01.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	15.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	15.02.2016	Grade 2 (Moderate)	.	.	athralgia
1	18.02.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18.02.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	18.02.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	23.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.02.2016	Grade 1 (Mild)	.	.	increase AST
1	23.02.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23.03.2016	Grade 1 (Mild)	.	.	hyperglycemia
1	23.03.2016		.	.	lengthen about qtcf
1	23.03.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 3 (Severe)	.	.	hypokalemia
1	23.03.2016	Grade 1 (Mild)	.	.	increase AST
1	23.03.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	21.04.2016	Grade 2 (Moderate)	.	.	hyperuricemia
1	21.04.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	21.04.2016	Grade 1 (Mild)	.	.	hypokalemia
1	19.05.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.05.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.06.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.06.2016	Grade 1 (Mild)	.	.	increase blood glucose
1	16.06.2016	Grade 1 (Mild)	.	.	increase AST
1	16.06.2016	Grade 4	.	.	hyperuricemia
1	19.07.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.07.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	19.07.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	19.07.2016	Grade 1 (Mild)	.	.	ALT increase
1	19.07.2016	Grade 2 (Moderate)	.	.	increase blood glucose
1	19.07.2016	Grade 1 (Mild)	.	.	increase AST
1	16.08.2016	Grade 1 (Mild)	.	.	hypokalemia
1	16.08.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	16.08.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.08.2016		.	.	lengthen about qtcf
1	03.10.2016		.	.	lengthen about qtcf
1	02.11.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	03.11.2016		.	.	lengthen about qtcf
1	22.11.2016	Grade 1 (Mild)	.	.	hypokalemia
1	22.11.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	22.11.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	01.12.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	01.12.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	01.12.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	22.12.2016	Grade 1 (Mild)	.	.	brown skin
1	22.12.2016	Grade 1 (Mild)	.	.	increase blood glucose
1	22.12.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	22.12.2016	Grade 1 (Mild)	.	.	increase AST
1	22.12.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.01.2017	Grade 3 (Severe)	.	.	hyperuricemia
1	19.01.2017	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	19.01.2017	Grade 1 (Mild)	.	.	increase blood glucose
1	19.01.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.02.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.02.2017	Grade 1 (Mild)	.	.	ALT increase
1	22.02.2017	Grade 1 (Mild)	.	.	lowering hemoglobin
1	22.02.2017	Grade 2 (Moderate)	.	.	increase blood glucose
1	22.02.2017	Grade 2 (Moderate)	.	.	increase AST
1	20.04.2017		.	.	lengthen about qtcf
1	23.05.2017		.	.	lengthen about qtcf
1	23.05.2017	Grade 2 (Moderate)	.	.	increase blood glucose
1	23.05.2017	Grade 3 (Severe)	.	.	hepatitis
1	23.05.2017	Grade 1 (Mild)	.	.	hyperuricemia
1	23.05.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.06.2017		.	.	lengthen about qtcf
1	22.08.2017	Grade 2 (Moderate)	.	.	hypokalemia
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Using this dataset above, I would like in my final table my rows start like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table want2.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36639i1895838D6E586FBE/image-size/large?v=v2&amp;amp;px=999" role="button" title="table want2.png" alt="table want2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this final table above I describe only 3 events how it should look like. The variable VISITDT is populating DATE_ONSET and DATE_END, and when there is adverse event (term2) interruption, it creates another row for the event. and so on...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;Kind regards.&lt;/P&gt;&lt;P&gt;Aljosa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Mar 2020 14:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630087#M186479</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-06T14:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630915#M186842</link>
      <description>&lt;P&gt;It took me some time, but I think this is it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='09'x dsd truncover;
input patient :$10. visitdt :ddmmyy10. INTENSITY :$20. (date_onset date_end) (:ddmmyy10.) term2 :$30.;
format visitdt date_onset date_end ddmmyy10.;
datalines;
1	31.12.2015	Grade 1 (Mild)	.	.	lowering hemoglobin
1	31.12.2015	Grade 1 (Mild)	.	.	hypokalemia
1	31.12.2015	Grade 1 (Mild)	.	.	increase blood glucose
1	31.12.2015	Grade 4	.	.	hyperuricemia
1	18.01.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	18.01.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	18.01.2016	Grade 1 (Mild)	.	.	increase AST
1	18.01.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	22.01.2016		.	.	lengthen about qtcf
1	22.01.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	15.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	15.02.2016	Grade 2 (Moderate)	.	.	athralgia
1	18.02.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	18.02.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	18.02.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	23.02.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.02.2016	Grade 1 (Mild)	.	.	increase AST
1	23.02.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	23.03.2016	Grade 1 (Mild)	.	.	hyperglycemia
1	23.03.2016		.	.	lengthen about qtcf
1	23.03.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	23.03.2016	Grade 3 (Severe)	.	.	hypokalemia
1	23.03.2016	Grade 1 (Mild)	.	.	increase AST
1	23.03.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	21.04.2016	Grade 2 (Moderate)	.	.	hyperuricemia
1	21.04.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	21.04.2016	Grade 1 (Mild)	.	.	hypokalemia
1	19.05.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.05.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.06.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.06.2016	Grade 1 (Mild)	.	.	increase blood glucose
1	16.06.2016	Grade 1 (Mild)	.	.	increase AST
1	16.06.2016	Grade 4	.	.	hyperuricemia
1	19.07.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.07.2016	Grade 2 (Moderate)	.	.	hypokalemia
1	19.07.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	19.07.2016	Grade 1 (Mild)	.	.	ALT increase
1	19.07.2016	Grade 2 (Moderate)	.	.	increase blood glucose
1	19.07.2016	Grade 1 (Mild)	.	.	increase AST
1	16.08.2016	Grade 1 (Mild)	.	.	hypokalemia
1	16.08.2016	Grade 1 (Mild)	.	.	hyperuricemia
1	16.08.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	16.08.2016		.	.	lengthen about qtcf
1	03.10.2016		.	.	lengthen about qtcf
1	02.11.2016	Grade 3 (Severe)	.	.	lowering hemoglobin
1	03.11.2016		.	.	lengthen about qtcf
1	22.11.2016	Grade 1 (Mild)	.	.	hypokalemia
1	22.11.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	22.11.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	01.12.2016	Grade 1 (Mild)	.	.	lowering blood calcium
1	01.12.2016	Grade 1 (Mild)	.	.	lowering hemoglobin
1	01.12.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	22.12.2016	Grade 1 (Mild)	.	.	brown skin
1	22.12.2016	Grade 1 (Mild)	.	.	increase blood glucose
1	22.12.2016	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	22.12.2016	Grade 1 (Mild)	.	.	increase AST
1	22.12.2016	Grade 3 (Severe)	.	.	hyperuricemia
1	19.01.2017	Grade 3 (Severe)	.	.	hyperuricemia
1	19.01.2017	Grade 2 (Moderate)	.	.	lowering hemoglobin
1	19.01.2017	Grade 1 (Mild)	.	.	increase blood glucose
1	19.01.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.02.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.02.2017	Grade 1 (Mild)	.	.	ALT increase
1	22.02.2017	Grade 1 (Mild)	.	.	lowering hemoglobin
1	22.02.2017	Grade 2 (Moderate)	.	.	increase blood glucose
1	22.02.2017	Grade 2 (Moderate)	.	.	increase AST
1	20.04.2017		.	.	lengthen about qtcf
1	23.05.2017		.	.	lengthen about qtcf
1	23.05.2017	Grade 2 (Moderate)	.	.	increase blood glucose
1	23.05.2017	Grade 3 (Severe)	.	.	hepatitis
1	23.05.2017	Grade 1 (Mild)	.	.	hyperuricemia
1	23.05.2017	Grade 2 (Moderate)	.	.	hypokalemia
1	22.06.2017		.	.	lengthen about qtcf
1	22.08.2017	Grade 2 (Moderate)	.	.	hypokalemia
;

/* create all visit dates for a patient */
proc sort
  data=have (keep=patient visitdt)
  out=all_dates
  nodupkey
;
by patient visitdt;
run;

proc sort data=have;
by patient visitdt term2;
run;

/* create a cartesian join, so we have all term2's for all dates */
proc sql;
create table all_dates_terms as
select distinct a.patient, a.visitdt, b.term2
from all_dates a, have b
where a.patient = b.patient;
quit;

/* join that back with have, but take intensity from there */
data all_have;
merge
  all_dates_terms (in=a)
  have (drop=date_onset date_end)
;
by patient visitdt term2;
if a;
run;

/* move term2 up in the sort order */
proc sort data=all_have;
by patient term2 visitdt;
run;

/* and now get the result */
data want (
  keep=patient term2 int date_onset date_end
  rename=(int=intensity)
);
set all_have;
by patient term2;
retain int date_onset date_end;
format date_onset date_end ddmmyyp10.;
if first.term2 then date_onset = .;
if intensity &amp;gt; '' and date_onset = . then date_onset = visitdt;
if intensity &amp;gt; int then int = intensity;
if intensity = ''
then do;
  if date_onset ne . then output;
  date_onset = .;
  int = '';
end;
date_end = visitdt;
if last.term2 and date_onset ne . and intensity &amp;gt; '' then output;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;patient    term2                     intensity             date_onset      date_end

   1       ALT increase              Grade 1 (Mild)        19.07.2016    19.07.2016
   1       ALT increase              Grade 1 (Mild)        22.02.2017    22.02.2017
   1       athralgia                 Grade 2 (Moderate)    15.02.2016    15.02.2016
   1       brown skin                Grade 1 (Mild)        22.12.2016    22.12.2016
   1       hepatitis                 Grade 3 (Severe)      23.05.2017    23.05.2017
   1       hyperglycemia             Grade 1 (Mild)        23.03.2016    23.03.2016
   1       hyperuricemia             Grade 4               31.12.2015    18.01.2016
   1       hyperuricemia             Grade 4               15.02.2016    16.08.2016
   1       hyperuricemia             Grade 3 (Severe)      22.11.2016    19.01.2017
   1       hyperuricemia             Grade 1 (Mild)        23.05.2017    23.05.2017
   1       hypokalemia               Grade 2 (Moderate)    31.12.2015    18.01.2016
   1       hypokalemia               Grade 2 (Moderate)    18.02.2016    18.02.2016
   1       hypokalemia               Grade 3 (Severe)      23.03.2016    21.04.2016
   1       hypokalemia               Grade 2 (Moderate)    19.07.2016    16.08.2016
   1       hypokalemia               Grade 1 (Mild)        22.11.2016    22.11.2016
   1       hypokalemia               Grade 2 (Moderate)    19.01.2017    22.02.2017
   1       hypokalemia               Grade 2 (Moderate)    23.05.2017    23.05.2017
   1       hypokalemia               Grade 2 (Moderate)    22.08.2017    22.08.2017
   1       increase AST              Grade 1 (Mild)        18.01.2016    18.01.2016
   1       increase AST              Grade 1 (Mild)        23.02.2016    23.03.2016
   1       increase AST              Grade 1 (Mild)        16.06.2016    19.07.2016
   1       increase AST              Grade 1 (Mild)        22.12.2016    22.12.2016
   1       increase AST              Grade 2 (Moderate)    22.02.2017    22.02.2017
   1       increase blood glucose    Grade 1 (Mild)        31.12.2015    31.12.2015
   1       increase blood glucose    Grade 2 (Moderate)    16.06.2016    19.07.2016
   1       increase blood glucose    Grade 2 (Moderate)    22.12.2016    22.02.2017
   1       increase blood glucose    Grade 2 (Moderate)    23.05.2017    23.05.2017
   1       lowering blood calcium    Grade 1 (Mild)        22.01.2016    22.01.2016
   1       lowering blood calcium    Grade 1 (Mild)        18.02.2016    18.02.2016
   1       lowering blood calcium    Grade 1 (Mild)        01.12.2016    01.12.2016
   1       lowering hemoglobin       Grade 1 (Mild)        31.12.2015    18.01.2016
   1       lowering hemoglobin       Grade 3 (Severe)      23.02.2016    16.08.2016
   1       lowering hemoglobin       Grade 3 (Severe)      02.11.2016    02.11.2016
   1       lowering hemoglobin       Grade 2 (Moderate)    22.11.2016    22.02.2017
&lt;/PRE&gt;
&lt;P&gt;For the three terms you gave as example, the results match.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 13:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630915#M186842</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-10T13:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: dates interruptions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630925#M186846</link>
      <description>&lt;P&gt;OMG this works!!! Its amazing ;)))) You are my life saver!!! Thank you million times dear Kurt!!! Have a wonderful day++++++++&lt;/P&gt;</description>
      <pubDate>Tue, 10 Mar 2020 14:05:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dates-interruptions/m-p/630925#M186846</guid>
      <dc:creator>Aljosa</dc:creator>
      <dc:date>2020-03-10T14:05:26Z</dc:date>
    </item>
  </channel>
</rss>

