<?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: select the last observation by id and date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897457#M354748</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.crsp_portno;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the last observation for a given crsp_portno, then you use the above. I realize that my sentence is not what you said. You said "last observation by id and date", in which case the code you showed ought to work fine (and so, what is wrong with it?) Which brings up another point ... please do NOT show us your code and then not even bother to tell us what is wrong with it.&lt;/P&gt;</description>
    <pubDate>Thu, 05 Oct 2023 19:38:45 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-10-05T19:38:45Z</dc:date>
    <item>
      <title>select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897449#M354747</link>
      <description>&lt;P&gt;hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to select the last observation by &lt;CODE class=" language-sas"&gt;crsp_portno &lt;/CODE&gt;and &lt;CODE class=" language-sas"&gt;REPORT_DT&amp;nbsp;(is a date)&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data first_by_group;
	set number_stocks ;
	by crsp_portno REPORT_DT;
 
	if  last.REPORT_DT then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Oct 2023 18:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897449#M354747</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-10-05T18:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897457#M354748</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last.crsp_portno;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the last observation for a given crsp_portno, then you use the above. I realize that my sentence is not what you said. You said "last observation by id and date", in which case the code you showed ought to work fine (and so, what is wrong with it?) Which brings up another point ... please do NOT show us your code and then not even bother to tell us what is wrong with it.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 19:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897457#M354748</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-05T19:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897492#M354749</link>
      <description>&lt;P&gt;hello,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the last observation by date and id or my code give the last observation by id only&lt;/P&gt;
&lt;P&gt;thanks a lot&lt;/P&gt;</description>
      <pubDate>Thu, 05 Oct 2023 21:49:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897492#M354749</guid>
      <dc:creator>sasphd</dc:creator>
      <dc:date>2023-10-05T21:49:57Z</dc:date>
    </item>
    <item>
      <title>Re: select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897496#M354750</link>
      <description>Time for a data example then. Fake data is fine, show what the input looks like and what you expect. &lt;BR /&gt;&lt;BR /&gt;FIRST/LAST will not handle multiple records per date for one thing. But typically these questions are selecting the correct first/last variables.</description>
      <pubDate>Thu, 05 Oct 2023 22:09:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897496#M354750</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-10-05T22:09:41Z</dc:date>
    </item>
    <item>
      <title>Re: select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897583#M354751</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4327"&gt;@sasphd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want the last observation by date and id or my code give the last observation by id only&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This doesn't make sense. Your code will give the last observation for each value of REPORT_DT. Please show us a portion of your actual data, provided as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 14:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897583#M354751</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-06T14:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: select the last observation by id and date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897653#M354752</link>
      <description>&lt;P&gt;Your code will produce one observation for each crsp_portno*report_dt combination.&amp;nbsp; So if some portfolios had multiple obs for a given report_dt, then you would get the last one of that set, for each report_dt.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set number_stocks ;
	by crsp_portno REPORT_DT; 
	if  last.REPORT_DT then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;suspect (and so do I) you likely have one record for each crsp_portno*report_dt combination, and you want only the last one. i.e. the most recent date for each portfolio.&amp;nbsp; If so, then&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;'s solution is what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this doesn't help, then please provide sample data, in the form of a working data step, and the expected output from that sample.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Oct 2023 04:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/select-the-last-observation-by-id-and-date/m-p/897653#M354752</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-07T04:09:20Z</dc:date>
    </item>
  </channel>
</rss>

