<?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: Extract missing dates and additional dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/936087#M367979</link>
    <description>&lt;P&gt;You're right.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jul 2024 20:14:08 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2024-07-17T20:14:08Z</dc:date>
    <item>
      <title>Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935261#M367731</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data sv ;
 input cpevent$1-8 svstdt $9-18 ;
  patient = "1015";
  svstdt1 = input(svstdt,date9.);
 cards ;
week0   20apr2022
week4   18may2022
week8   20jun2022
week26  19oct2022
week30  22nov2022
week34  14dec2022
week52  18apr2023
week56  17may2023
week60  19jun2023
week78  17oct2023
week82  15nov2023
week86  13dec2023
week104 17apr2024
;

Data qs ;
 patient = "1015";
 do qsdat = '22apr2022'd to '25apr2022'd,'18may2022'd to '20may2022'd,
 '21jun2022'd,'19oct2022'd to '22oct2022'd,'14dec2022'd to '17dec2022'd,
 '18apr2023'd to '21apr2023'd ,'17may2023'd to '19may2023'd,'19jun2023'd to '21jun2023'd,
 '19oct2023'd to '22oct2023'd,'15nov2023'd to '18nov2023'd,
 '13dec2023'd to '16dec2023'd,'18apr2024'd ;
 output;
 end ;
 format qsdat date9.;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I need help in programming based on below conditions :&lt;/P&gt;
&lt;P&gt;Created above data based on my real time study, And&amp;nbsp; Requiredoutput dataset also below attached.&lt;/P&gt;
&lt;P&gt;(This is emergency requirement for my study)&lt;BR /&gt;for the svstdt check the below logics :&lt;BR /&gt;1)for day0 check if qsdat = svstdt ,if yes populate the qsdat inday0 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;2)for day1 check if qsdat = svstdt+1 ,if yes populate the qsdat in day1 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;3)for day2 check if qsdat = svstdt+2 ,if yes populate the qsdat in day2 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;4)for day3 check if qsdat = svstdt+3 ,if yes populate the qsdat in day3 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;if any columns from day0 ,day1,day2,day3 is blank &lt;BR /&gt;then populate flag as "missing"&lt;BR /&gt;if additional records were received in qsdat which is outside of &lt;BR /&gt;above defined days (day1,day1,day2,day3)&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;I am tried below programme everything okay but not getting additional records :&lt;/P&gt;
&lt;P&gt;Please any one correct it .&lt;/P&gt;
&lt;P&gt;data sv_qs;&lt;BR /&gt;if _n_ = 1 then do;&lt;BR /&gt;declare hash h(dataset:'qs');&lt;BR /&gt;h.defineKey('patient', 'qsdat');&lt;BR /&gt;h.defineData('qsdat');&lt;BR /&gt;h.defineDone();&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;set sv;&lt;BR /&gt;&lt;BR /&gt;array days[*] day0-day3 additional ;&lt;BR /&gt;do i = 0 to 4;&lt;BR /&gt;rc = h.find(key:patient, key:svstdt1+i);&lt;BR /&gt;if rc = 0 then days[i+1] = svstdt1+i;&lt;BR /&gt;/* else days[i+1] =.;*/&lt;BR /&gt;end;&lt;BR /&gt;&lt;BR /&gt;rc = h.find(key:patient, key:qsdat);&lt;BR /&gt;if rc = 0 and qsdat &amp;lt; svstdt1 or qsdat &amp;gt; svstdt1 + 3 then flag = "extra";&lt;BR /&gt;&lt;BR /&gt;format qsdat additional additional1 day0 day1 day2 day3 date9. ;&lt;BR /&gt;drop rc i;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 06:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935261#M367731</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2024-07-10T06:38:31Z</dc:date>
    </item>
    <item>
      <title>extract additional and missing records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935259#M367882</link>
      <description>&lt;PRE&gt;&lt;CODE class=""&gt;Data sv ;
 input cpevent$1-8 svstdt $9-18 ;
  patient = "1015";
 cards ;
week0   20apr2022
week4   18may2022
week8   20jun2022
week26  19oct2022
week30  22nov2022
week34  14dec2022
week52  18apr2023
week56  17may2023
week60  19jun2023
week78  17oct2023
week82  15nov2023
week86  13dec2023
week104 17apr2024
;

Data qs ;
 patient = "1015";
 do qsdat = '22apr2022'd to '25apr2022'd,'18may2022'd to '20may2022'd,
 '21jun2022'd,'19oct2022'd to '22oct2022'd,'14dec2022'd to '17dec2022'd,
 '18apr2023'd to '21apr2023'd ,'17may2023'd to '19may2023'd,'19jun2023'd to '21jun2023'd,
 '19oct2023'd to '22oct2023'd,'15nov2023'd to '18nov2023'd,
 '13dec2023'd to '16dec2023'd,'18apr2024'd ;
 output;
 end ;
 format qsdat date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need help in programming for below condition. Iam created above data based on my real time project. Required output dataset also attached. Output same as attached Dataset below.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;for the svstdt check the below logics :&lt;BR /&gt;1)for day0 check if qsdat = svstdt ,if yes populate the qsdat inday0 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;2)for day1 check if qsdat = svstdt+1 ,if yes populate the qsdat in day1 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;3)for day2 check if qsdat = svstdt+2 ,if yes populate the qsdat in day2 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;4)for day3 check if qsdat = svstdt+3 ,if yes populate the qsdat in day3 column.&lt;BR /&gt;keep lt blank&lt;BR /&gt;if any columns from day0 ,day1,day2,day3 is blank&lt;BR /&gt;then populate flag as "missing"&lt;BR /&gt;if additional records were received in qsdat which is outside of&lt;BR /&gt;above defined days (day1,day1,day2,day3)&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 03:57:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935259#M367882</guid>
      <dc:creator>110816</dc:creator>
      <dc:date>2024-07-10T03:57:51Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935688#M367865</link>
      <description>&lt;P&gt;I don't see any DAY&lt;EM&gt;n&lt;/EM&gt; column.&lt;/P&gt;
&lt;P&gt;Please post the expected result as a table as some of us can't/won't download files.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jul 2024 06:36:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935688#M367865</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-13T06:36:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935693#M367867</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2024-07-13 124144.png" style="width: 856px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98385i400C04DDAF76B029/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2024-07-13 124144.png" alt="Screenshot 2024-07-13 124144.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jul 2024 07:14:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935693#M367867</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2024-07-13T07:14:31Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935694#M367868</link>
      <description>Based on the conditions mentioned above and two datasets, I need output like the attached image.&lt;BR /&gt;I also pasted my program also (My sample programme)</description>
      <pubDate>Sat, 13 Jul 2024 07:18:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935694#M367868</guid>
      <dc:creator>112211</dc:creator>
      <dc:date>2024-07-13T07:18:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935734#M367875</link>
      <description>&lt;P&gt;You could do everything in one data step, but it's easier to code and follow the logic if you save the additional dates in a subsequent step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data SV ;
  retain PATIENT '1015';
  input CPEVENT :$8. SVSTDTE :date9. ;
  format SVSTDTE date9.;
cards ;
week0   20apr2022
week4   18may2022
week8   20jun2022
week26  19oct2022
week30  22nov2022
week34  14dec2022
week52  18apr2023
week56  17may2023
week60  19jun2023
week78  17oct2023
week82  15nov2023
week86  13dec2023
week104 17apr2024
;

data QS;
  retain PATIENT '1015';
  do QSDTE = '22apr2022'd to '25apr2022'd, '18may2022'd to '20may2022'd, '21jun2022'd,
             '19oct2022'd to '22oct2022'd, '14dec2022'd to '17dec2022'd,
             '18apr2023'd to '21apr2023'd, '17may2023'd to '19may2023'd, 
             '19jun2023'd to '21jun2023'd, '19oct2023'd to '22oct2023'd,
             '15nov2023'd to '18nov2023'd, '13dec2023'd to '16dec2023'd, '18apr2024'd ;
    output;
  end;
  format QSDTE date9.;
run;

data FILLDAYS;

  %* Define lookup table for QS date;
  if _n_ = 1 then do;
    if 0 then set QS;
    declare hash H(dataset:'QS', ordered: 'y');
    h.defineKey( 'PATIENT', 'QSDTE');
    h.defineData('PATIENT', 'QSDTE');
    h.defineDone();
  end;

  %* Read SV date and next SV date ;
  set SV nobs=NOBS;
  if _N_ ne NOBS then set SV(keep=SVSTDTE rename=(SVSTDTE=NEXTDTE) firstobs=2);
  else NEXTDTE='31DEC2999'd;
  
  %* Declare DAYn variables;
  array DAYS[*] DAY0-DAY3 ;
  format DAY0-DAY3 date9. ;
  
  %* Populate DAYn variables;
  do I = 0 to 3;
    RC = H.find(key:PATIENT, key:SVSTDTE+I);    
    if RC = 0 then do;
      DAYS[I+1] = SVSTDTE+I;
      H.remove(key:PATIENT, key:SVSTDTE+I);  
    end;  
  end;
  
  %* Set missing flag;
  if nmiss(of DAY:)=4 then FLAG = 'missing';
  
  %* Export unused QS dates;
  if _N_=NOBS then H.output(dataset:'ADD1'); 
  
  %* Clean up;
  drop RC I;
run;

%* Assign additional dates to correct interval;
proc sql;
  create table ADD2 as
  select FILLDAYS.*, ADD1.QSDTE as ADDDTE
  from FILLDAYS
         left join
       ADD1
         on  FILLDAYS.PATIENT = ADD1.PATIENT 
         and ADD1.QSDTE between FILLDAYS.QSDTE and FILLDAYS.NEXTDTE
  order by FILLDAYS.PATIENT, FILLDAYS.QSDTE  ;
run;  

%* Final table, concatenate additional dates ;
data WANT;
  set ADD2;  
  length ADDITIONAL $80 ;
  retain ADDITIONAL;
  by PATIENT QSDTE;
  if ADDDTE then do;
    if first.QSDTE then ADDITIONAL=put(ADDDTE,date9.);
    else ADDITIONAL=catx('.', ADDITIONAL, put(ADDDTE,date9.));
  end;
  if last.QSDTE then do;
    output; 
    ADDITIONAL=' ';
  end;
  keep PATIENT CPEVENT DAY: ADDITIONAL;
run;  
&lt;/CODE&gt;&lt;/PRE&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="ChrisNZ_1-1720935958612.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/98396i88D398AE4E4BDEAC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ChrisNZ_1-1720935958612.png" alt="ChrisNZ_1-1720935958612.png" /&gt;&lt;/span&gt;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 05:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935734#M367875</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-14T05:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935735#M367876</link>
      <description>&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Why do you post exactly the same question under a different name?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/extract-additional-and-missing-records/m-p/935259" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/extract-additional-and-missing-records/m-p/935259&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 05:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935735#M367876</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-14T05:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935746#M367883</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT size="5"&gt;&lt;STRONG&gt;Why do you post exactly the same question under a different name?&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/extract-additional-and-missing-records/m-p/935259" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/extract-additional-and-missing-records/m-p/935259&lt;/A&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That post has now been merged with this one.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 12:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935746#M367883</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-14T12:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935748#M367885</link>
      <description>I'd have reported the other one as spam rather than merge.&lt;BR /&gt;Why 2 different names?</description>
      <pubDate>Sun, 14 Jul 2024 13:27:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935748#M367885</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-14T13:27:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935753#M367886</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'd have reported the other one as spam rather than merge.&lt;BR /&gt;Why 2 different names?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If there are two different names for this wholly identical post, then it may be that these are classmates asking about a homework task.&amp;nbsp; If so, I think there is a benefit to merging.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jul 2024 15:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935753#M367886</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-14T15:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935766#M367889</link>
      <description>&lt;P&gt;The posts are exactly the same, same formatting, same attachment. And the user names too: six digits. Quite unusual.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Jul 2024 05:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/935766#M367889</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-15T05:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extract missing dates and additional dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/936087#M367979</link>
      <description>&lt;P&gt;You're right.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jul 2024 20:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-missing-dates-and-additional-dates/m-p/936087#M367979</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-17T20:14:08Z</dc:date>
    </item>
  </channel>
</rss>

