<?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: How to create an advanced expression formula with two specific time periods? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732388#M38497</link>
    <description>&lt;P&gt;I think the query builder is strictly SQL, which does not honor the lag function.&lt;/P&gt;</description>
    <pubDate>Fri, 09 Apr 2021 02:53:29 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-04-09T02:53:29Z</dc:date>
    <item>
      <title>How to create an advanced expression formula with two specific time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732376#M38494</link>
      <description>&lt;P&gt;Hello All!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am somewhat new to SAS EG and came across this problem. Currently, I am moving a project from excel into SAS and I am trying to figure out a solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, I am trying to figure out a percent change from two specific periods. For example, the percent formula I am trying to re-create if (Fall 2019 DegreeCount) - (Fall 2018 DegreeCount) / (Fall 2018 DegreeCount). In excel it was done manually such as (G19-G20)/G20. How can I do that here in SAS enterprise guide?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example Data:&lt;/P&gt;&lt;P&gt;AcademicYr TermCode TermYear&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;School of Major&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DegreeCount&amp;nbsp; &amp;nbsp; CertCount&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 201970&amp;nbsp; &amp;nbsp; &amp;nbsp;Fall 2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; School A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 45&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 201980&amp;nbsp; &amp;nbsp; &amp;nbsp;Spring 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; School B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 120&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/P&gt;&lt;P&gt;2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 201990&amp;nbsp; &amp;nbsp; &amp;nbsp;Summer 2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;School C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&lt;/P&gt;&lt;P&gt;2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 201870&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Fall 2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; School A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;201880&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Spring 2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; School B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;300&lt;/P&gt;&lt;P&gt;2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 201890&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;Summer 2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;School C&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 200&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Apr 2021 23:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732376#M38494</guid>
      <dc:creator>andimo89</dc:creator>
      <dc:date>2021-04-08T23:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an advanced expression formula with two specific time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732379#M38495</link>
      <description>&lt;P&gt;Since SAS keeps only one "row" of data in memory at a time, you can't exactly replicate access to row 19 when calculating a value in row 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you can use the "lag" function, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if termyear=:'Fall' then pct_change=divide(dif(degreecount),lag(degreecount));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; Whenever termyear starts with 'Fall' the lag function updates a fifo queue, by extracting the last time it was invoked (i.e. the previous "Fall") and storing the current value into the queue.&amp;nbsp; In this case the lag function is a queue of size 1&amp;nbsp; &amp;nbsp;("lag2" would have a size of 2, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dif function in nothing more than current degreecount minus the lagged value of degreecount (i.e. the change in degreecount.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if I had done this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  if termyear=:'Fall' then pct_change=dif(degreecount)/lag(degreecount);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would get the same numeric results, but also an error message because the first instance of "Fall" would retrieve a missing lagged value, which would cause this log note:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;1 at xxx:42 1 at xxx:59&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Using the DIVIDE function instead avoided the note.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 00:45:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732379#M38495</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-09T00:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an advanced expression formula with two specific time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732384#M38496</link>
      <description>&lt;P&gt;I appreciate your reply. I apologize for not having the proper nomenclature for this but could this be done inside they query builder. I am incredible novice at SAS code and was wondering if this can be done from the advanced expression button inside of a query builder.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 01:27:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732384#M38496</guid>
      <dc:creator>andimo89</dc:creator>
      <dc:date>2021-04-09T01:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create an advanced expression formula with two specific time periods?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732388#M38497</link>
      <description>&lt;P&gt;I think the query builder is strictly SQL, which does not honor the lag function.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Apr 2021 02:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-create-an-advanced-expression-formula-with-two-specific/m-p/732388#M38497</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-04-09T02:53:29Z</dc:date>
    </item>
  </channel>
</rss>

