<?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 explain to me what does the following data step do &amp;quot;especially the bold big syntax&amp;quot;  please email it to me or comment here email(nkogatsetj@gmail.com) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107832#M30041</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First. and Last. are fairly well explained in SAS documentation. You may want to search and read it for yourself. In the mean time, here's my quick explanation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use BY group processing (statement by customer_key;), SAS creates 2 additionnal automatic variables per by variable to help you process your groups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume the following statement:&lt;/P&gt;&lt;P&gt;by var1 var2 var3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then SAS creates&lt;/P&gt;&lt;P&gt;first.var1 last.var1&lt;/P&gt;&lt;P&gt;first.var2 last.var2&lt;/P&gt;&lt;P&gt;first.var3 last.var3&lt;/P&gt;&lt;P&gt;automatic variables. They are binary (0 or 1) variables that indicate whether the current record is the first (Resp. last) in the current group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since FALSE=0 and TRUE=1, the statement IF last.customer_key then output; is equivalent logically to IF last.customer_key=TRUE then output;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, the above statement controls your output and only outputs the last record for each distinct customer_key in query_for_cust_e_0002 to mart.fica_lock_up&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Imagine the following data set that you read with a BY var1 var2 var3; statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rownum var1 var2 var3&lt;/P&gt;&lt;P&gt;1 1 1 1&lt;/P&gt;&lt;P&gt;2 1 2 1&lt;/P&gt;&lt;P&gt;3 1 2 2&lt;/P&gt;&lt;P&gt;4 1 2 3&lt;/P&gt;&lt;P&gt;5 1 3 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the Above, first.var1 = 1 only for rownum=1. Last.var1=1 only for rownum=5&lt;/P&gt;&lt;P&gt;first.var2=1 for each rownum in (1, 2, 5) and last.var2=1 for each rownum in (1, 4, 5)&lt;/P&gt;&lt;P&gt;first.var3=1 for each rownum in (1,2,3,4,5) and last.var3=1 for each rownum in (1,2,3,4,5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, the first and last automatic variables created allow you, for example, to reset counters, reset sums to 0 or products to 1 for your desired by group. They also allow you control over time series where you are only interested in values at the begining and end of a by group, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 09 Oct 2013 14:27:51 GMT</pubDate>
    <dc:creator>Vince28_Statcan</dc:creator>
    <dc:date>2013-10-09T14:27:51Z</dc:date>
    <item>
      <title>Please explain to me what does the following data step do "especially the bold big syntax"  please email it to me or comment here email(nkogatsetj@gmail.com)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107830#M30039</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;&lt;A href="mailto:nkogatsetj@gmail.com)DAta"&gt;DAta&lt;/A&gt;&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Mart.Fica_Lock_up;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; WORK.QUERY_FOR_CUST_E_0002;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; Customer_Key;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 14pt;"&gt;&lt;STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt; last.Customer_key &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;Run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Oct 2013 13:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107830#M30039</guid>
      <dc:creator>tebogo</dc:creator>
      <dc:date>2013-10-09T13:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: Please explain to me what does the following data step do "especially the bold big syntax"  please email it to me or comment here email(nkogatsetj@gmail.com)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107831#M30040</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It outputs to dataset Mart.Fica_Lock_up the LAST sorted observation of every by group (in this case by-groups of the variable customer_key).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It might be helpful if your title line spoke about the actual problem you have instead of how the problem is identified in the text (example: What does "if last.customer_key" do)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Oct 2013 14:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107831#M30040</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2013-10-09T14:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Please explain to me what does the following data step do "especially the bold big syntax"  please email it to me or comment here email(nkogatsetj@gmail.com)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107832#M30041</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First. and Last. are fairly well explained in SAS documentation. You may want to search and read it for yourself. In the mean time, here's my quick explanation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you use BY group processing (statement by customer_key;), SAS creates 2 additionnal automatic variables per by variable to help you process your groups.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assume the following statement:&lt;/P&gt;&lt;P&gt;by var1 var2 var3;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;then SAS creates&lt;/P&gt;&lt;P&gt;first.var1 last.var1&lt;/P&gt;&lt;P&gt;first.var2 last.var2&lt;/P&gt;&lt;P&gt;first.var3 last.var3&lt;/P&gt;&lt;P&gt;automatic variables. They are binary (0 or 1) variables that indicate whether the current record is the first (Resp. last) in the current group.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since FALSE=0 and TRUE=1, the statement IF last.customer_key then output; is equivalent logically to IF last.customer_key=TRUE then output;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, the above statement controls your output and only outputs the last record for each distinct customer_key in query_for_cust_e_0002 to mart.fica_lock_up&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Imagine the following data set that you read with a BY var1 var2 var3; statement:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;rownum var1 var2 var3&lt;/P&gt;&lt;P&gt;1 1 1 1&lt;/P&gt;&lt;P&gt;2 1 2 1&lt;/P&gt;&lt;P&gt;3 1 2 2&lt;/P&gt;&lt;P&gt;4 1 2 3&lt;/P&gt;&lt;P&gt;5 1 3 1&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the Above, first.var1 = 1 only for rownum=1. Last.var1=1 only for rownum=5&lt;/P&gt;&lt;P&gt;first.var2=1 for each rownum in (1, 2, 5) and last.var2=1 for each rownum in (1, 4, 5)&lt;/P&gt;&lt;P&gt;first.var3=1 for each rownum in (1,2,3,4,5) and last.var3=1 for each rownum in (1,2,3,4,5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thus, the first and last automatic variables created allow you, for example, to reset counters, reset sums to 0 or products to 1 for your desired by group. They also allow you control over time series where you are only interested in values at the begining and end of a by group, etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;Vince&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Oct 2013 14:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Please-explain-to-me-what-does-the-following-data-step-do-quot/m-p/107832#M30041</guid>
      <dc:creator>Vince28_Statcan</dc:creator>
      <dc:date>2013-10-09T14:27:51Z</dc:date>
    </item>
  </channel>
</rss>

