<?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: wrangle data to compare previous record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744946#M233451</link>
    <description>Many Thanks !!  Your code works perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  !</description>
    <pubDate>Tue, 01 Jun 2021 14:43:30 GMT</pubDate>
    <dc:creator>dennis_oz</dc:creator>
    <dc:date>2021-06-01T14:43:30Z</dc:date>
    <item>
      <title>wrangle data to compare previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744852#M233410</link>
      <description>&lt;P&gt;Hi friends ,&lt;/P&gt;
&lt;P&gt;I was wanting some help on the below&amp;nbsp; . I need to compare the Service_Dates and if the Service date is present in the above record create an Flag='Y'.&lt;/P&gt;
&lt;P&gt;My input data is attached as an excel&amp;nbsp;&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="dennis_oz_0-1622516642887.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59912i065D43DE1D98587D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_0-1622516642887.png" alt="dennis_oz_0-1622516642887.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, the input code in a data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.check3;
     INPUT
        id $1-8  SERVICE_DATES $10-69 cntr $70-72 ;
		datalines;
267005668 20210401 || 20210401 || 20210401 || 20210401 || 20210401    3
267005668 20210401 || 20210401 || 20210401 || 20210401	              3
245060165 20200512 || 20200512	                                      9
245060165 20191212 || 20191212 || 20191212 || 20191212 || 20191212	  9
241777762 20210407                                                    10
241777762 20210407 || 20210407 || 20210407 || 20210407	              10
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please can you help with my query .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 03:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744852#M233410</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2021-06-01T03:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: wrangle data to compare previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744874#M233416</link>
      <description>&lt;P&gt;Do you always have non-overlapping pairs of records to compare?&amp;nbsp; I.e., do you only compare record 2 to 1, 4 to 3, 6 to 5, but not 3 to 2, 5 to 4, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also why are you reading all your date variables as one long string?&amp;nbsp; Why not read each date value as a separate variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally, it seems that within each record containing multiple dates, those dates are always the same.&amp;nbsp; Is that the case for your entire dataset?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 05:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744874#M233416</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-01T05:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: wrangle data to compare previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744878#M233417</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; ,&lt;/P&gt;
&lt;P&gt;this is the way I am receiving the data .&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have further wrangled the data into below . I want to check now if a value in service_dates occurs in service_dates_new . If so just create a new column flag .&lt;/P&gt;
&lt;P&gt;Please see my desied output in the last screen shot under output&amp;nbsp;&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="dennis_oz_1-1622527206539.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59922iCDA517250770136F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_1-1622527206539.png" alt="dennis_oz_1-1622527206539.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;input code&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DATA WORK.check3;
     INPUT
        id $1-9  SERVICE_DATES $10-69 cntr $70-72  SERVICE_DATES_NEW $74-130;
		datalines;
267005668 20210401 || 20210401 || 20210401 || 20210423 || 20210401    1   20210423 
245060165 20200512 || 20200512	                                      2   20191212 || 20191212 || 20191212 || 20191212 || 20191212
241777762 20210407                                                    3  20210407 || 20210407 || 20210407 || 20210407	
RUN;
&lt;/PRE&gt;
&lt;P&gt;output&lt;/P&gt;
&lt;P&gt;======&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dennis_oz_2-1622527565086.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/59923iEB48281022B73669/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dennis_oz_2-1622527565086.png" alt="dennis_oz_2-1622527565086.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 06:07:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744878#M233417</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2021-06-01T06:07:07Z</dc:date>
    </item>
    <item>
      <title>Re: wrangle data to compare previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744910#M233431</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.check3;
     INPUT
        id $1-8  SERVICE_DATES $10-69 cntr $70-72 ;
		datalines;
267005668 20210401 || 20210401 || 20210401 || 20210401 || 20210401    3
267005668 20210401 || 20210401 || 20210401 || 20210401	              3
245060165 20200512 || 20200512	                                      9
245060165 20191212 || 20191212 || 20191212 || 20191212 || 20191212	  9
241777762 20210407                                                    10
241777762 20210407 || 20210407 || 20210407 || 20210407	              10
;
RUN;

data want;
 set check3;
 lag=lag(SERVICE_DATES);
 if id=lag(id) then do;
   flag='Y';
   do i=1 to countw(SERVICE_DATES,'|');
     temp=scan(SERVICE_DATES,i,'|');
	 if not find(lag,strip(temp)) then do;
       flag=' ';leave;
	 end;
   end;
 end;
drop lag temp i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 01 Jun 2021 12:15:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744910#M233431</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-01T12:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: wrangle data to compare previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744946#M233451</link>
      <description>Many Thanks !!  Your code works perfectly &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;  !</description>
      <pubDate>Tue, 01 Jun 2021 14:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/wrangle-data-to-compare-previous-record/m-p/744946#M233451</guid>
      <dc:creator>dennis_oz</dc:creator>
      <dc:date>2021-06-01T14:43:30Z</dc:date>
    </item>
  </channel>
</rss>

