<?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: Lag Functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725336#M225281</link>
    <description>&lt;P&gt;So here are the prior steps that led to this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new indicator variable to identify years where a restatement was issued.&amp;nbsp; If FILE_DATE is greater than 0, RESTATEMENT should equal 1 and otherwise should be 0.&lt;/LI&gt;&lt;LI&gt;Using PROC SQL, perform an inner join to merge Audit Fees 2 and Firm Data.&amp;nbsp; Merge observatiosn where COMPANY_FKEY equals CIK and observations have the same fiscal year (FYEAR).&lt;/LI&gt;&lt;LI&gt;Using the lag function, create an indicator variable, PY_RESTATEMENT, coded 1 if the company issued a restatement in the prior year, and coded 0 otherwise.&lt;/LI&gt;&lt;LI&gt;Create a variable, NEW_AUDITOR, coded 1 if the auditor in the current year is not the same as the auditor in the prior year, and 0 otherwise.&lt;UL&gt;&lt;LI&gt;Hint: First use the lag function to create prior GVKEY and prior AUDITOR_FKEY variables.&amp;nbsp; Then delete observations where prior GVKEY and GVKEY are not the same (i.e. the firm changed from one row to the next).&amp;nbsp; Finally, for the remaining observations, create an indicator variable coded 1 if the auditor identifier and prior year identifier (AUDITOR_FKEY) are not the same.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;The mean value of NEW_AUDITOR is the percentage of observations where there was a new auditor.&amp;nbsp; Obtain the mean value of NEW_AUDITOR for observations where PY_RESTATEMENT is equal to one and observations where PY_RESTATEMENT is equal to 0.&amp;nbsp; Are firms more likely to get a new auditor if they issued a restatement in the prior year?&lt;UL&gt;&lt;LI&gt;Hint: You may have to research how to use the proc means command for groups.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Basically I want to lag when restatement = 1 or 0. However I, unfortunately, have to use the lag statement to get full credit. I don't know how to lag, really, so the last 3 statements are impossible for me.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Mar 2021 03:53:55 GMT</pubDate>
    <dc:creator>krg1140</dc:creator>
    <dc:date>2021-03-11T03:53:55Z</dc:date>
    <item>
      <title>Lag Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725331#M225276</link>
      <description>&lt;P&gt;&lt;STRONG&gt;7&amp;nbsp;&lt;/STRONG&gt;Using the lag function, create an indicator variable, PY_RESTATEMENT, coded 1 if the company issued a restatement in the prior year, and coded 0 otherwise.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data sql.Firm_data; set sql.Firm_data;&lt;BR /&gt;py_restatement=lag(restatement);&lt;BR /&gt;if restatement ne lag(restatement) then py_restatement=1;&lt;BR /&gt;else py_restatement=0;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;however this isn't working, any ideas?&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 02:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725331#M225276</guid>
      <dc:creator>krg1140</dc:creator>
      <dc:date>2021-03-11T02:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725335#M225280</link>
      <description>&lt;P&gt;What does "issued a restatement in the prior year" mean?&lt;/P&gt;
&lt;P&gt;What does the RESTATEMENT variable contain?&lt;BR /&gt;How many firms are in the dataset?&lt;BR /&gt;Is the dataset order by firm and year?&lt;BR /&gt;Are there any missing years?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please share some sample data with expected results.&lt;/P&gt;
&lt;P&gt;Hint: Do not overwrite your input dataset, that will make debugging impossible because you no longer have the original input.&lt;/P&gt;
&lt;P&gt;Try one of these.&lt;/P&gt;
&lt;P&gt;If RESTATEMENT is already a 1/0 (true false) flag variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  py_restatement=lag(restatement);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If RESTATEMENT having a non-zero or&amp;nbsp; non-missing value means there was a restatement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  py_restatement= not not lag(restatement);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 03:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725335#M225280</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-11T03:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725336#M225281</link>
      <description>&lt;P&gt;So here are the prior steps that led to this:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Create a new indicator variable to identify years where a restatement was issued.&amp;nbsp; If FILE_DATE is greater than 0, RESTATEMENT should equal 1 and otherwise should be 0.&lt;/LI&gt;&lt;LI&gt;Using PROC SQL, perform an inner join to merge Audit Fees 2 and Firm Data.&amp;nbsp; Merge observatiosn where COMPANY_FKEY equals CIK and observations have the same fiscal year (FYEAR).&lt;/LI&gt;&lt;LI&gt;Using the lag function, create an indicator variable, PY_RESTATEMENT, coded 1 if the company issued a restatement in the prior year, and coded 0 otherwise.&lt;/LI&gt;&lt;LI&gt;Create a variable, NEW_AUDITOR, coded 1 if the auditor in the current year is not the same as the auditor in the prior year, and 0 otherwise.&lt;UL&gt;&lt;LI&gt;Hint: First use the lag function to create prior GVKEY and prior AUDITOR_FKEY variables.&amp;nbsp; Then delete observations where prior GVKEY and GVKEY are not the same (i.e. the firm changed from one row to the next).&amp;nbsp; Finally, for the remaining observations, create an indicator variable coded 1 if the auditor identifier and prior year identifier (AUDITOR_FKEY) are not the same.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;The mean value of NEW_AUDITOR is the percentage of observations where there was a new auditor.&amp;nbsp; Obtain the mean value of NEW_AUDITOR for observations where PY_RESTATEMENT is equal to one and observations where PY_RESTATEMENT is equal to 0.&amp;nbsp; Are firms more likely to get a new auditor if they issued a restatement in the prior year?&lt;UL&gt;&lt;LI&gt;Hint: You may have to research how to use the proc means command for groups.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Basically I want to lag when restatement = 1 or 0. However I, unfortunately, have to use the lag statement to get full credit. I don't know how to lag, really, so the last 3 statements are impossible for me.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 03:53:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725336#M225281</guid>
      <dc:creator>krg1140</dc:creator>
      <dc:date>2021-03-11T03:53:55Z</dc:date>
    </item>
    <item>
      <title>Re: Lag Functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725426#M225331</link>
      <description>&lt;P&gt;I don't think the LAG() part is really that hard for this.&lt;/P&gt;
&lt;P&gt;Your step 3 is really just the code I showed before.&amp;nbsp; If you have already created RESTATEMENT as 0/1 flag variable then the simple LAG(RESTATEMENT) will get you the value of RESTATEMENT from the previous observation.&amp;nbsp; The key thing is that the data needs to be ordered properly, otherwise the previous value of restatement is not the previous year's value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you need to take into account that you have multiple company.&amp;nbsp; You don't want the flag on the first observation for a company to have the value from the last observation for the previous company.&lt;/P&gt;
&lt;P&gt;Let's use COMPANY and YEAR as the variables that define the company and the year.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by company year ;
  py_restatement=lag(restatement);
  if first.company then py_restatement=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Mar 2021 13:24:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Lag-Functions/m-p/725426#M225331</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-11T13:24:03Z</dc:date>
    </item>
  </channel>
</rss>

