<?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: Splitting a dataset using first. and last. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273367#M54475</link>
    <description>&lt;P&gt;Thank you for the solution - and for explaining why!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Janet&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2016 19:20:27 GMT</pubDate>
    <dc:creator>janet0102</dc:creator>
    <dc:date>2016-05-26T19:20:27Z</dc:date>
    <item>
      <title>Splitting a dataset using first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273354#M54468</link>
      <description>&lt;P&gt;I've got a dataset with a maximum of 2 observations per ID (patid) and another variable that identifies the individual as being part of the study group (pain_id=1) or part of the comparison group (pain_id=0). Some individuals only have 1 observation and others have 2. I also have a variable with identifying the variable as the first or the second observation. I want to create a dataset containing individuals with only one observation and pain_id=1, a dataset containg only individuals with one observation and pain_id. Then I want a dataset for individuals having 2 observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Following is the syntax I'm using:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data pnpts nonpts twoobs;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;set allpts_count;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;by patid;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (first.patid and last.patid)and pain_id=1 then output pnpts;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if (first.patid and last.patid) and pain_id=0 then output nonpts;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else output twoobs;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm able to create the 1st two datasets (pnpts and nonpts) correctly. However, the dataset twoobs contains both observations for individuals with 2 observations; but it also contains the individuals from the dataset pnpts even when they only have one observation. Twoobs does not contain the individuals from the dataset nonpts (who have only one observation).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why am I getting the individuals from pnpts in the dataset twoobs - and more importantly, how do I prevent it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Janet&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 18:49:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273354#M54468</guid>
      <dc:creator>janet0102</dc:creator>
      <dc:date>2016-05-26T18:49:55Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a dataset using first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273359#M54472</link>
      <description>&lt;P&gt;Hi Janet,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Put an ELSE before the second IF and everything should be fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without that, the existing ELSE statement refers only to the second IF, hence it includes the cases satisfying the first IF condition, but not the second.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 18:57:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273359#M54472</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-05-26T18:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a dataset using first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273360#M54473</link>
      <description>&lt;P&gt;Please provide sample data in executable code (datalines) so we can test your code.&lt;/P&gt;
&lt;P&gt;If you are using SAS Foundation, you could try the data step debugger that lets monitor the execution step by step.&lt;/P&gt;
&lt;P&gt;Another option it to use put&amp;nbsp;statements to monitor the progress of your&amp;nbsp;program and variable values.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 19:01:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273360#M54473</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-05-26T19:01:00Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a dataset using first. and last.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273367#M54475</link>
      <description>&lt;P&gt;Thank you for the solution - and for explaining why!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Janet&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2016 19:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-dataset-using-first-and-last/m-p/273367#M54475</guid>
      <dc:creator>janet0102</dc:creator>
      <dc:date>2016-05-26T19:20:27Z</dc:date>
    </item>
  </channel>
</rss>

