<?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 keep last baseline value for duplicate records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548690#M152186</link>
    <description>&lt;P&gt;also in continuity of my previous reply.&lt;/P&gt;
&lt;P&gt;if you are looking to remove the duplicates completely from your record then you can use nodupkey in proc sort, as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want nodupkey;
by visitnum visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Apr 2019 06:09:35 GMT</pubDate>
    <dc:creator>Shivam</dc:creator>
    <dc:date>2019-04-05T06:09:35Z</dc:date>
    <item>
      <title>How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548646#M152164</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a screenshot of the data where there is a duplicate record.&amp;nbsp; My goal is to keep LBBLFL='Y' for only the last record (second record in this case) .&amp;nbsp;&amp;nbsp; I tried using last.visit, but didn't work. thanks&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="Capture.JPG" style="width: 552px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/28451iB205AD589BE46C41/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 20:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548646#M152164</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2019-04-04T20:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548648#M152165</link>
      <description>&lt;P&gt;So here you want to delete the first observation only and keep the rest in the data set, correct?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 20:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548648#M152165</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-04-04T20:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548649#M152166</link>
      <description>&lt;P&gt;&lt;EM&gt;"&amp;nbsp;I tried using last.visit, &lt;U&gt;but didn't work&lt;/U&gt;"&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why is that?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What was the result?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 20:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548649#M152166</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-04T20:52:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548658#M152173</link>
      <description>&lt;P&gt;Actual example data as a data step is helpful as I am not going to type in data.&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Likely you used 1) the wrong variable visit_num and the wrong test.&lt;/P&gt;
&lt;P&gt;In the following example the variable B plays the role of visit_num, a is the llbblfl and c is the lbdtc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   input a b c;
datalines;
1 2 3
1 2 5
. 3 2
. 3 4
;

data want;
   set example;
   by b c;
   if not(last.b) then call missing(a);
run;&lt;/PRE&gt;
&lt;P&gt;if there are other variables involved, such as an ID variable or more you would sort by those plus visit_num and LBDTC.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not to use visit? To use by processing and first and last the data needs to be sorted. And believe it or not&amp;nbsp;DAY50 comes before DAY8.&lt;/P&gt;
&lt;PRE&gt;data example;
   input a $;
datalines;
DAY-1
DAY8
DAY50
;

proc sort data=example ;
   by a;
run;

proc print; run;&lt;/PRE&gt;
&lt;P&gt;Why? Character comparisons for order stop with the first different character and 5&amp;lt;8.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can get around this with proc sort but the data step doesn't really understand the difference and getting NOTSORTED in the right place may be tricky depending on the actual data involved.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Apr 2019 21:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548658#M152173</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-04T21:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548689#M152185</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume that in your data you can have visit day as different for same visit?(obviously it doesn't make sense, but since you have highlighted the visitnum and visit both the columns, i assume visit day can be different for same visitnum)&lt;/P&gt;
&lt;P&gt;in that case you can use the following code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input visitnum visit $;
cards;
1 day1
1 day1
2 day4
1 day1
2 day4
2 day4
3 day7
2 day4
3 day5
4 day6
4 day8
;
run;
proc sort data=have;
by visitnum visit;
run;

data want;
set have;
by visitnum visit;
if last.visit then flag='Y'&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2019 06:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548689#M152185</guid>
      <dc:creator>Shivam</dc:creator>
      <dc:date>2019-04-05T06:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep last baseline value for duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548690#M152186</link>
      <description>&lt;P&gt;also in continuity of my previous reply.&lt;/P&gt;
&lt;P&gt;if you are looking to remove the duplicates completely from your record then you can use nodupkey in proc sort, as below&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=want nodupkey;
by visitnum visit;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Apr 2019 06:09:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-last-baseline-value-for-duplicate-records/m-p/548690#M152186</guid>
      <dc:creator>Shivam</dc:creator>
      <dc:date>2019-04-05T06:09:35Z</dc:date>
    </item>
  </channel>
</rss>

