<?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 Create two datasets from one dataset in SAS Health and Life Sciences</title>
    <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28783#M1110</link>
    <description>I am trying to split a dataset into two datasets. My dataset consists of three variables, patient, note_date, note. For example, the dataset has many patients and each patient has many records. I am trying to determine what is the first visit date for each patient and then seperate the dataset into one dataset containg all patients with their first visits only and a dataset with all patients with all visits except the first one. For clarity the patient can have more than one first visit date. I tried using first. but can't seem to work out the logic. Any help is appreciated.</description>
    <pubDate>Tue, 01 Jul 2008 14:28:23 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-07-01T14:28:23Z</dc:date>
    <item>
      <title>Create two datasets from one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28783#M1110</link>
      <description>I am trying to split a dataset into two datasets. My dataset consists of three variables, patient, note_date, note. For example, the dataset has many patients and each patient has many records. I am trying to determine what is the first visit date for each patient and then seperate the dataset into one dataset containg all patients with their first visits only and a dataset with all patients with all visits except the first one. For clarity the patient can have more than one first visit date. I tried using first. but can't seem to work out the logic. Any help is appreciated.</description>
      <pubDate>Tue, 01 Jul 2008 14:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28783#M1110</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-01T14:28:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create two datasets from one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28784#M1111</link>
      <description>Well I figured this one out. &lt;BR /&gt;
&lt;BR /&gt;
My code is below.&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=progressnotes;&lt;BR /&gt;
	by pat_name note_date;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data temp;&lt;BR /&gt;
    set progressnotes;&lt;BR /&gt;
	format n_date mmddyy10.;&lt;BR /&gt;
	n_date=DATEPART(note_date);&lt;BR /&gt;
run; &lt;BR /&gt;
&lt;BR /&gt;
data temp;&lt;BR /&gt;
	set temp;&lt;BR /&gt;
	retain first_visit;&lt;BR /&gt;
	format first_visit mmddyy10.;&lt;BR /&gt;
	by pat_name note_date;&lt;BR /&gt;
	if first.pat_name then do; &lt;BR /&gt;
		first_visit=n_date;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 01 Jul 2008 15:19:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28784#M1111</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-01T15:19:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create two datasets from one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28785#M1112</link>
      <description>Hi:&lt;BR /&gt;
  In order to streamline your code, this construction:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
  set temp;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
is not needed. Since progressnotes is sorted and you are creating n_date only for the purpose of creating first_visit for every obs in a patient group, you can do everything you need in one data step program. You might, instead, consider code like this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sort data=progressnotes;&lt;BR /&gt;
  by pat_name note_date;&lt;BR /&gt;
run;&lt;BR /&gt;
                &lt;BR /&gt;
data temp;&lt;BR /&gt;
  retain first_visit;&lt;BR /&gt;
  format first_visit mmddyy10.&lt;BR /&gt;
         n_date mmddyy10.;&lt;BR /&gt;
          &lt;BR /&gt;
  set progressnotes;&lt;BR /&gt;
  by pat_name note_date;&lt;BR /&gt;
       &lt;BR /&gt;
  n_date=DATEPART(note_date);&lt;BR /&gt;
       &lt;BR /&gt;
  if first.pat_name then do; &lt;BR /&gt;
     first_visit=n_date;&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
If you don't want a separate n_date on every obs, then you could just have&lt;BR /&gt;
[pre]&lt;BR /&gt;
  first_visit=datepart(note_date);&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
But you must have wanted a separate n_date on every obs, since you put it there in a separate data step program. At any rate, you can create n_date and first_visit in the same program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Tue, 01 Jul 2008 18:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28785#M1112</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2008-07-01T18:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create two datasets from one dataset</title>
      <link>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28786#M1113</link>
      <description>Thanks Cynthia,&lt;BR /&gt;
&lt;BR /&gt;
I don't mind shortening my code.</description>
      <pubDate>Tue, 01 Jul 2008 18:29:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Health-and-Life-Sciences/Create-two-datasets-from-one-dataset/m-p/28786#M1113</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-07-01T18:29:38Z</dc:date>
    </item>
  </channel>
</rss>

