<?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: extract the first record for each observation in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2156#M719</link>
    <description>Hello Alt, &lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if this is what you're trying to do but getting the first observation of each By group can easily be done with SAS code:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sashelp.prdsale out=test;&lt;BR /&gt;
by product;run;&lt;BR /&gt;
&lt;BR /&gt;
data prdsale;&lt;BR /&gt;
  set test;&lt;BR /&gt;
  by product;&lt;BR /&gt;
if first.product then output;&lt;BR /&gt;
else delete;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Is this what you're trying to do?&lt;BR /&gt;
I'm not sure if there is a built in task that does this in EG but you could add this as a code node in your process flow or insert it as custom code in your task node.</description>
    <pubDate>Thu, 25 Jan 2007 14:13:15 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2007-01-25T14:13:15Z</dc:date>
    <item>
      <title>extract the first record for each observation</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2155#M718</link>
      <description>How do i extract the first record post grouping the observations in EG.&lt;BR /&gt;
&lt;BR /&gt;
Thanks &amp;amp; would appreciate any help&lt;BR /&gt;
Cheers&lt;BR /&gt;
ALT</description>
      <pubDate>Wed, 24 Jan 2007 22:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2155#M718</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-24T22:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: extract the first record for each observation</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2156#M719</link>
      <description>Hello Alt, &lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if this is what you're trying to do but getting the first observation of each By group can easily be done with SAS code:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=sashelp.prdsale out=test;&lt;BR /&gt;
by product;run;&lt;BR /&gt;
&lt;BR /&gt;
data prdsale;&lt;BR /&gt;
  set test;&lt;BR /&gt;
  by product;&lt;BR /&gt;
if first.product then output;&lt;BR /&gt;
else delete;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Is this what you're trying to do?&lt;BR /&gt;
I'm not sure if there is a built in task that does this in EG but you could add this as a code node in your process flow or insert it as custom code in your task node.</description>
      <pubDate>Thu, 25 Jan 2007 14:13:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2156#M719</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-01-25T14:13:15Z</dc:date>
    </item>
    <item>
      <title>Re: extract the first record for each observation</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2157#M720</link>
      <description>If you agree to include some code in your EG project, the previous answer is the simplest you can do. If you want to stick to EG "point-and-click" way of life, I suggest the following...&lt;BR /&gt;
Start a query on your data.&lt;BR /&gt;
Compute 2 new variables :&lt;BR /&gt;
1) one named "SEQUENCE" (for example) with the following formula : MONOTONIC()&lt;BR /&gt;
2) one named "FIRST" with the following formula : MIN(CALCULATED sequence)&lt;BR /&gt;
The SEQUENCE variable will consist in numbers given to each data line, in a sequential way (hence its name) : 1, 2, 3, ... The FIRST variable will compute the minimum sequence number for each group. Don't forget to add in the query interface that the FIRST variable is to be computed for each group !&lt;BR /&gt;
&lt;BR /&gt;
One last thing : in the "Group Filtering" tab, add the condition that SEQUENCE = FIRST. And then you're done.&lt;BR /&gt;
The SAS code produced should somehow look like this :&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL ;&lt;BR /&gt;
	SELECT *,&lt;BR /&gt;
		   MONOTONIC() AS order,&lt;BR /&gt;
		   MIN(CALCULATED order) AS first&lt;BR /&gt;
	FROM sashelp.class&lt;BR /&gt;
	GROUP BY age&lt;BR /&gt;
	HAVING order = first&lt;BR /&gt;
	;&lt;BR /&gt;
QUIT ;&lt;BR /&gt;
&lt;BR /&gt;
This gives you the first child for each group of Age, from the SASHELP.CLASS dataset.</description>
      <pubDate>Fri, 26 Jan 2007 11:25:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/extract-the-first-record-for-each-observation/m-p/2157#M720</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2007-01-26T11:25:52Z</dc:date>
    </item>
  </channel>
</rss>

