<?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: Please provide the answer using first.id and last.id concept in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311407#M67291</link>
    <description>&lt;P&gt;First do a proc sort by name and class.&lt;/P&gt;
&lt;P&gt;Then, in a data step, use &lt;FONT face="courier new,courier"&gt;by name class;&lt;/FONT&gt; again.&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if first.class then newmarks = 0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to initialize at every group change, use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;newmarks + marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to add the marks up (this syntax for summarization automatically makes newmarks a retained variable).&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if last.class then output;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to write out the summarized observations&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;drop marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;rename newmarks=marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to create the old structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Nov 2016 14:17:11 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-14T14:17:11Z</dc:date>
    <item>
      <title>Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311404#M67289</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Question: &lt;/STRONG&gt;Dataset schoolx is given as :&lt;/P&gt;&lt;P&gt;data schoolx;&lt;BR /&gt;input Name $ Class $ Marks;&lt;BR /&gt;cards;&lt;BR /&gt;AAA X 20&lt;BR /&gt;AAA Y 30&lt;BR /&gt;AAA Z 40&lt;BR /&gt;AAA X 50&lt;BR /&gt;BBB X 60&lt;BR /&gt;BBB Y 70&lt;BR /&gt;BBB X 20&lt;BR /&gt;CCC X 10&lt;BR /&gt;CCC Y 40&lt;BR /&gt;CCC Z 50&lt;BR /&gt;CCC Z 30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Generate the following output from the above dataset:&lt;BR /&gt;AAA X 70&lt;BR /&gt;AAA Y 30&lt;BR /&gt;AAA Z 40&lt;BR /&gt;BBB X 80&lt;BR /&gt;BBB Y 70&lt;BR /&gt;CCC X 10&lt;BR /&gt;CCC Y 40&lt;BR /&gt;CCC Z 80&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 14:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311404#M67289</guid>
      <dc:creator>ROHINISDAS</dc:creator>
      <dc:date>2016-11-14T14:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311407#M67291</link>
      <description>&lt;P&gt;First do a proc sort by name and class.&lt;/P&gt;
&lt;P&gt;Then, in a data step, use &lt;FONT face="courier new,courier"&gt;by name class;&lt;/FONT&gt; again.&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if first.class then newmarks = 0;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to initialize at every group change, use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;newmarks + marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to add the marks up (this syntax for summarization automatically makes newmarks a retained variable).&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if last.class then output;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to write out the summarized observations&lt;/P&gt;
&lt;P&gt;use&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;drop marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;rename newmarks=marks;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to create the old structure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 14:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311407#M67291</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-14T14:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311412#M67293</link>
      <description>&lt;P&gt;Is there any specific reason for using first.id and last.id. You can use proc means instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=schoolx;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;by&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; name class;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;MEANS&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;=schoolx &lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;sum&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;class&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; name class;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;var&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt; marks;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 14:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311412#M67293</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2016-11-14T14:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311413#M67294</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt; select Name,Class,sum(Marks) as Marks from schoolx group by Name,Class;&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 14:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311413#M67294</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2016-11-14T14:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311418#M67297</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data schoolx;
input Name $ Class $ Marks;
cards;
AAA X 20
AAA Y 30
AAA Z 40
AAA X 50
BBB X 60
BBB Y 70
BBB X 20
CCC X 10
CCC Y 40
CCC Z 50
CCC Z 30
;
run;

proc sort data = schoolx;
   by Name Class;
run;

data want;
   set schoolx;
   by Name Class;

   if first.class = 1 then do;
      newmarks = 0;
      newmarks = newmarks + marks;
   end;

   else newmarks = newmarks + marks;
   
   if last.class then output;
   retain newmarks;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Nov 2016 14:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311418#M67297</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-14T14:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311446#M67308</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;can u please help me to explain with the output what exactly happens with this portion of code.I meant how first.class and last.class is working here.?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if first.class then newmarks = 0;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;to initialize at every group change, use&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;newmarks + marks;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;to add the marks up (this syntax for summarization automatically makes newmarks a retained variable).&lt;/P&gt;&lt;P&gt;use&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if last.class then output;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;to write out the summarized observations&lt;/P&gt;&lt;P&gt;use&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;drop marks;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;rename newmarks=marks;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;to create the old structure.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 16:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311446#M67308</guid>
      <dc:creator>ROHINISDAS</dc:creator>
      <dc:date>2016-11-14T16:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311457#M67314</link>
      <description>&lt;P&gt;Read the very good &lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n138da4gme3zb7n1nifpfhqv7clq.htm" target="_blank"&gt;SAS documentation on by group processing&lt;/A&gt;, and you will find the answer yourself.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2016 16:46:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311457#M67314</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-14T16:46:24Z</dc:date>
    </item>
    <item>
      <title>Re: Please provide the answer using first.id and last.id concept</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311490#M67337</link>
      <description>thanks</description>
      <pubDate>Mon, 14 Nov 2016 19:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Please-provide-the-answer-using-first-id-and-last-id-concept/m-p/311490#M67337</guid>
      <dc:creator>ROHINISDAS</dc:creator>
      <dc:date>2016-11-14T19:13:13Z</dc:date>
    </item>
  </channel>
</rss>

