<?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: Count duplicates in date order in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45739#M12059</link>
    <description>OK.&lt;BR /&gt;
&lt;BR /&gt;
I'll try not to give you that one free. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
They are several approaches for your question.&lt;BR /&gt;
&lt;BR /&gt;
I'll point only one.&lt;BR /&gt;
&lt;BR /&gt;
My understanding, is that you want to summarize your data by PERSON, but retaining the ADMISSIONs whenever there is an 'X' within the group.&lt;BR /&gt;
&lt;BR /&gt;
So you simply need to work within the group, retaining the value of each admission.&lt;BR /&gt;
&lt;BR /&gt;
the RETAIN statement will do precisely that. Hold the last variable value within each datastep iteration.&lt;BR /&gt;
&lt;BR /&gt;
See the online documentation:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
To summarize your data, you just need to work with the FIRST / LAST statement (which will indicate if the iteration is at the top, middle, or bottom of the group) and perform an explicit output when desired (here, tipically at the end).&lt;BR /&gt;
&lt;BR /&gt;
See the online docmentation here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001349233.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001349233.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Combine these two features in one datastep, and you'll have your problem solved.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
    <pubDate>Thu, 18 Jun 2009 14:32:19 GMT</pubDate>
    <dc:creator>DanielSantos</dc:creator>
    <dc:date>2009-06-18T14:32:19Z</dc:date>
    <item>
      <title>Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45729#M12049</link>
      <description>Hi &lt;BR /&gt;
&lt;BR /&gt;
I have a dataset with admissions to hospitals in a 5 year period. I have the admissions numbered with an admission id number and an additional people id number to identify the different inidividuals in the dataset. Some individuals have more than one admission to the hospital and these cases will have different admission id numbers but the same people id number. I want to count how many admissions each person in the dataset has and order these according to dates.&lt;BR /&gt;
&lt;BR /&gt;
Can anyone please help me.</description>
      <pubDate>Wed, 17 Jun 2009 07:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45729#M12049</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T07:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45730#M12050</link>
      <description>For the counting, a simple sql query will do the job.&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select ID_PERSON, count(*) as COUNT from ADMISSIONS group by ID_PERSON;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Not sure about what you wish to do with the date ordering.&lt;BR /&gt;
&lt;BR /&gt;
Do you want to order the counts by the lastes admission date?&lt;BR /&gt;
Or do you wish to simply order the ADMISSIONS dataset?&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;

Message was edited by: Daniel Santos</description>
      <pubDate>Wed, 17 Jun 2009 08:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45730#M12050</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-17T08:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45731#M12051</link>
      <description>It's unclear if you already have a SAS dataset or an external file and in what format -- you can use a DATA step to read an external file, while creating a SAS numeric DATE type variable for your admin date.  With that file read up, then SAS PROC SUMMARY can complete this task.  Or you may want to explore using SAS PROC SQL to group the observations based on the admin ID.&lt;BR /&gt;
&lt;BR /&gt;
There is SAS-host documentation and technical/conference papers on this type of topic, available at the SAS support  &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt;  website, either using the website SEARCH facility or a Google advanced search adding on the site:sas.com  parameter to limit the search.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
SAS DATA Step Processing&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
SAS 9.2 Language Concepts - About SAS Date, Time, and Datetime Values&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002200738.htm&lt;/A&gt;</description>
      <pubDate>Wed, 17 Jun 2009 08:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45731#M12051</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-17T08:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45732#M12052</link>
      <description>Thank you for your responses!&lt;BR /&gt;
&lt;BR /&gt;
I can see, that I havent been that clear about what I wanted, so I will try and explain it in another way - sorry!&lt;BR /&gt;
&lt;BR /&gt;
In our dataset the cases are admissions. We would like to turn the dataset around to turn the individuals into the cases. Thereby we make the admissions into variables. If an individual has more than one admission, we would like to number these admissions according to admission date - and thereby make new variables, each indicating which number admission it is.&lt;BR /&gt;
&lt;BR /&gt;
Hope that you can help me</description>
      <pubDate>Wed, 17 Jun 2009 09:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45732#M12052</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-17T09:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45733#M12053</link>
      <description>Much more clearer now.&lt;BR /&gt;
&lt;BR /&gt;
OK, forget my previous suggestion.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data = ADMISSIONS;&lt;BR /&gt;
by ID_PERSON DATE;&lt;BR /&gt;
run; /* sort */&lt;BR /&gt;
&lt;BR /&gt;
data ADMISSIONS_C;&lt;BR /&gt;
set ADMISSIONS;&lt;BR /&gt;
by ID_PERSON;&lt;BR /&gt;
if first.ID_PERSON the COUNT=0; /* reset counter */&lt;BR /&gt;
COUNT+1; /* count admission, implicitly retained */&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Wed, 17 Jun 2009 09:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45733#M12053</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-17T09:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45734#M12054</link>
      <description>Honestly, your use of "variables" reference is still unclear, at least to me, in comparison to data rows (in SAS called observations).  Best to paste in your reply some INPUT side data rows/columns and OUTPUT side (desired) rows/columns for review/comment and feedback.&lt;BR /&gt;
&lt;BR /&gt;
For myself, I will hope to attempt to lead you with some ideas for SAS programming techniques -- others may decide to do the programming for you, which, in my opinion, defeats the opportunity (with each post) for learning the SAS language by trying.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 17 Jun 2009 11:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45734#M12054</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-17T11:59:09Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45735#M12055</link>
      <description>Got the message Scott.&lt;BR /&gt;
&lt;BR /&gt;
Not being english my natural language, it is sometimes difficult for me to explain some matters with letters, it's way more simple to just code it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
But I agree with you, and I'll make an effort to explain my suggestion rather than give them away.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Wed, 17 Jun 2009 15:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45735#M12055</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-17T15:25:52Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45736#M12056</link>
      <description>Fair point Scott.&lt;BR /&gt;
On the other hand, I would argue that giving working code still allows the reader to learn from it (if the reader makes the effort obviously). &lt;BR /&gt;
I would even argue that one can learn more from well-written code (even though definitions for this will vary) than from fiddling with badly understood language features.&lt;BR /&gt;
Lastly, giving working code also proves the proposed solution actually works, rather than giving ideas that may or may not answer the question. &lt;BR /&gt;
To each their own, as usual... &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 18 Jun 2009 01:25:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45736#M12056</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-06-18T01:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45737#M12057</link>
      <description>Thank you Daniel!&lt;BR /&gt;
&lt;BR /&gt;
That was very helpful - and I think that I actually did learn from it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
However, I have entered a new problem. &lt;BR /&gt;
After having sorted the admissions and created the new "count" variable, I have created a new variable for each admission, that is, I have said: &lt;BR /&gt;
&lt;BR /&gt;
If count=0 then admission1="X";&lt;BR /&gt;
If count=1 then admission2="X";&lt;BR /&gt;
and so on..&lt;BR /&gt;
&lt;BR /&gt;
The problem is now, that individuals, who have had more than one admission will appear in the new datasat more than one time. The viewtable looks like this:&lt;BR /&gt;
&lt;BR /&gt;
				&lt;BR /&gt;
	              Count	   Admission 1	Admission 2	Admission 3&lt;BR /&gt;
Person A	         1                   x		&lt;BR /&gt;
Person A	         2		                        x        &lt;BR /&gt;
Person A	         3		                                                 x&lt;BR /&gt;
				&lt;BR /&gt;
&lt;BR /&gt;
What I would like, is that the individuals (here: person A) only appear one time in the view table - but that all information about each of the admissions is available. That is, a viewtable like this:&lt;BR /&gt;
         	&lt;BR /&gt;
	              Admission 1	Admission 2	Admission 3&lt;BR /&gt;
Person A  		     x	                        x	                x&lt;BR /&gt;
&lt;BR /&gt;
Can anyone help me with this?&lt;BR /&gt;
&lt;BR /&gt;
Thank you!</description>
      <pubDate>Thu, 18 Jun 2009 12:34:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45737#M12057</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-18T12:34:14Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45738#M12058</link>
      <description>Sorry - the tables i had put in, have changed. This was what I meant: &lt;BR /&gt;
&lt;BR /&gt;
I want to change from this view table: &lt;BR /&gt;
...............Count...........Admission1...........Admission2..........Admission3&lt;BR /&gt;
Person A.....1.....................x&lt;BR /&gt;
Person A.....2.................................................x&lt;BR /&gt;
Person A.....3............................................................................x&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
To this: &lt;BR /&gt;
...................Admission1............Admission2...............Admission3&lt;BR /&gt;
Person A.............x............................x.............................x</description>
      <pubDate>Thu, 18 Jun 2009 12:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45738#M12058</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-18T12:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45739#M12059</link>
      <description>OK.&lt;BR /&gt;
&lt;BR /&gt;
I'll try not to give you that one free. &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;BR /&gt;
&lt;BR /&gt;
They are several approaches for your question.&lt;BR /&gt;
&lt;BR /&gt;
I'll point only one.&lt;BR /&gt;
&lt;BR /&gt;
My understanding, is that you want to summarize your data by PERSON, but retaining the ADMISSIONs whenever there is an 'X' within the group.&lt;BR /&gt;
&lt;BR /&gt;
So you simply need to work within the group, retaining the value of each admission.&lt;BR /&gt;
&lt;BR /&gt;
the RETAIN statement will do precisely that. Hold the last variable value within each datastep iteration.&lt;BR /&gt;
&lt;BR /&gt;
See the online documentation:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
To summarize your data, you just need to work with the FIRST / LAST statement (which will indicate if the iteration is at the top, middle, or bottom of the group) and perform an explicit output when desired (here, tipically at the end).&lt;BR /&gt;
&lt;BR /&gt;
See the online docmentation here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001349233.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001349233.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Combine these two features in one datastep, and you'll have your problem solved.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Thu, 18 Jun 2009 14:32:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45739#M12059</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-18T14:32:19Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45740#M12060</link>
      <description>Hi Daniel,&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your last response.&lt;BR /&gt;
I have tried all weekend to use the retain and first/last statements in the correct way, but I am not succeeding... &lt;BR /&gt;
I would really appreciate if you could help me a bit more with how to solve the problem. &lt;BR /&gt;
&lt;BR /&gt;
Thank you very much! &lt;BR /&gt;
&lt;BR /&gt;
:-) Christina</description>
      <pubDate>Mon, 22 Jun 2009 07:40:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45740#M12060</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-22T07:40:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45741#M12061</link>
      <description>Okay, you've tried. Fair enough. ;D&lt;BR /&gt;
&lt;BR /&gt;
data OUT (drop = _:); /* drop old vars */&lt;BR /&gt;
set IN (rename = (ADMISSION1=_A1 ADMISSION2=_A2 ADMISSION3=_A3));&lt;BR /&gt;
by PERSON; /* input dataset MUST BE sorted by PERSON */&lt;BR /&gt;
retain ADMISSION1 '' ADMISSION2 '' ADMISSION3 ''; /* new vars */&lt;BR /&gt;
&lt;BR /&gt;
/* reset _A* vars for each PERSON group start */&lt;BR /&gt;
if first.PERSON then do;&lt;BR /&gt;
ADMISSION1=''; ADMISSION2=''; ADMISSION3='';&lt;BR /&gt;
end; &lt;BR /&gt;
&lt;BR /&gt;
/* coalescec returns the first non empty value of a list */&lt;BR /&gt;
ADMISSION1=coalescec(_A1,ADMISSION1);&lt;BR /&gt;
ADMISSION2=coalescec(_A2,ADMISSION2);&lt;BR /&gt;
ADMISSION3=coalescec(_A3,ADMISSION3);&lt;BR /&gt;
&lt;BR /&gt;
/* output last record only */&lt;BR /&gt;
if last.PERSON;&lt;BR /&gt;
&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Now, in the above solution, new ADMISSION vars are created (retained) based on the old ones, which will be dropped at the end of the datastep.&lt;BR /&gt;
At each group start, new vars are reset to '', and for each group row, the result of the coalescec function is assigned (coalescec function returns the first non empty value of a list). Finally, and since you need only row per group, output to the dataset is perform only at the last row of the group.&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Mon, 22 Jun 2009 10:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45741#M12061</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-22T10:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45742#M12062</link>
      <description>Without a LENGTH statement in the above code, you will have a 1-char variable for ADMISSION1-ADMISSION3.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 22 Jun 2009 12:00:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45742#M12062</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-06-22T12:00:46Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45743#M12063</link>
      <description>Good point.&lt;BR /&gt;
&lt;BR /&gt;
I assumed by christina's example ('X') that a 1 char length was enough.&lt;BR /&gt;
If it isn't, you should explicitly alocate the new vars with the LENGTH statement.&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000218807.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000218807.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Mon, 22 Jun 2009 13:39:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45743#M12063</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-22T13:39:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45744#M12064</link>
      <description>Hi Daniel&lt;BR /&gt;
&lt;BR /&gt;
Thank you for the coding! One character is enough.&lt;BR /&gt;
&lt;BR /&gt;
I have som trouble getting the coding to work. I have started with the retain statement but I cannot make it work- even with a simple coding. This is what I am doing:&lt;BR /&gt;
&lt;BR /&gt;
data out;&lt;BR /&gt;
set in;&lt;BR /&gt;
by person_id;&lt;BR /&gt;
retain ad1;&lt;BR /&gt;
ad1=admission1;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
After running this statement my ad1 variable is exactly the same as my admission1 variable- the ad1 has not retained any values. Do you know what I am doing wrong?&lt;BR /&gt;
&lt;BR /&gt;
Thanks again for your help&lt;BR /&gt;
&lt;BR /&gt;
:) Cristina</description>
      <pubDate>Mon, 22 Jun 2009 16:02:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45744#M12064</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-06-22T16:02:50Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45745#M12065</link>
      <description>Christina, &lt;BR /&gt;
Your &lt;BR /&gt;
[pre]ad1=admission1;[/pre] line is always executed, so the retained value is always over-written by the data set value.&lt;BR /&gt;
Something like&lt;BR /&gt;
[pre]if admission1 ne '' then ad1=admission1;[/pre] will ensure that the retained value is only overwritten if there is a valid value to use.&lt;BR /&gt;
&lt;BR /&gt;
PS Your ID reads Christina, you sign Cristina. Are both interchangeable?</description>
      <pubDate>Mon, 22 Jun 2009 23:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45745#M12065</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-06-22T23:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count duplicates in date order</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45746#M12066</link>
      <description>Exactly.&lt;BR /&gt;
&lt;BR /&gt;
You should assign the value of one variable to another, only if the first is not empty ('').&lt;BR /&gt;
&lt;BR /&gt;
coalescec function is another way of doing the same.&lt;BR /&gt;
&lt;BR /&gt;
See: &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002518268.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a002518268.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;</description>
      <pubDate>Tue, 23 Jun 2009 11:29:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-duplicates-in-date-order/m-p/45746#M12066</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-06-23T11:29:59Z</dc:date>
    </item>
  </channel>
</rss>

