<?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: Correct use of the &amp;quot;first.&amp;quot; statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98018#M20688</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I often make this mistake. I have to go back and do a PROC SORT using the variable in the BY statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 05 Feb 2013 15:29:36 GMT</pubDate>
    <dc:creator>happyuser</dc:creator>
    <dc:date>2013-02-05T15:29:36Z</dc:date>
    <item>
      <title>Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98016#M20686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi! I am working on a sas code including a loop to make a sum of food intakes. Every subject has an ID and for each ID I have different strings, one for each food item consumed during the day. The goal is to obtain the total amount eaten every day by each subject, i.e.: the sum of each food variable for every ID.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the program I am using, which seems correct to me, but SAS keep saying that the variable first.id_no is not initialized:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data dataset; set dataset; &lt;/P&gt;&lt;P&gt;if first.id_no then do; sum0 = 0; sum1 = 0; sum2 = 0; sum3 = 0; end;&lt;/P&gt;&lt;P&gt;sum0 = sum0 + intake*(vegetables = 1);&lt;/P&gt;&lt;P&gt;sum1 = sum1 + intake*(fruit = 1);&lt;/P&gt;&lt;P&gt;sum2 = sum2 + intake*(cereals = 1);&lt;/P&gt;&lt;P&gt;sum3 = sum3 + intake*(fish = 1);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Alternatively I have tried to write:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (first.id_no) then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if first.id_no = 1 then do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;always getting the same error message from SAS.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your help!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 14:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98016#M20686</guid>
      <dc:creator>Foodscience_76</dc:creator>
      <dc:date>2013-02-05T14:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98017#M20687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure about your code is doing what you want, but to make use of first. you must declare the column in a BY statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 15:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98017#M20687</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-02-05T15:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98018#M20688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I often make this mistake. I have to go back and do a PROC SORT using the variable in the BY statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 15:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98018#M20688</guid>
      <dc:creator>happyuser</dc:creator>
      <dc:date>2013-02-05T15:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98019#M20689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In order to user the "first" and "last" you need to sort your data by the variable (in your case - id_no).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc sort data=dataset;&lt;/P&gt;&lt;P&gt;by id_no;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;set dataset&lt;/P&gt;&lt;P&gt;by id_no;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if first.id_no then&amp;nbsp;&amp;nbsp; ...etc....&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 15:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98019#M20689</guid>
      <dc:creator>OS2Rules</dc:creator>
      <dc:date>2013-02-05T15:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98020#M20690</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;Foodscience_76 wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;The goal is to obtain the total amount eaten every day by each subject, i.e.: the sum of each food variable for every ID.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;If this is your goal you will be better off using a procedure like MEANS/SUMMARY.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 16:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98020#M20690</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-02-05T16:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Correct use of the "first." statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98021#M20691</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you everybody for your help! It was in fact very simple, just sorting and adding a BY statement. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 05 Feb 2013 16:05:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Correct-use-of-the-quot-first-quot-statement/m-p/98021#M20691</guid>
      <dc:creator>Foodscience_76</dc:creator>
      <dc:date>2013-02-05T16:05:01Z</dc:date>
    </item>
  </channel>
</rss>

