<?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 Novice Question:  How to Create a Computed Column Based on Row Values in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105032#M9166</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am starting to learn SAS EG and using it for my dissertation.&amp;nbsp; I am not sure if I have to run code or if I can do the following in the computed column interface:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THE PROBLEM:&lt;/P&gt;&lt;P&gt;I have a table (STATE) that (to simplify) consists of the following columns: &lt;/P&gt;&lt;P&gt;StateYRKey, State, Year, ChgYr1, ChgYear5, ChgYear10, GSP&amp;nbsp; (e.g.,&amp;nbsp; AK1960, AK, 1960, 1961, 1965, 1970, 123456)&lt;/P&gt;&lt;P&gt;I want to create a computed column for various changes in GSP (again simplifying) Yr1GSPChg, Yr5GSPChg, Yr10GSPChg&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to code something like (or simplier):&lt;/P&gt;&lt;P&gt;For i in {AK..WY} Do&lt;/P&gt;&lt;P&gt;&amp;nbsp; For j = {1960..2012} Do&lt;/P&gt;&lt;P&gt;&amp;nbsp; BEGIN&lt;/P&gt;&lt;P&gt; * The key is a concatenation.&amp;nbsp; I want to access values for specific rows to compute the appropriate difference)&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; STATE.(Concatenate i,j).Yr1GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -1).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; STATE.(Concatenate i,j).Yr5GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -5).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; STATE.(Concatenate i,j).Yr10GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -10).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp; END&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In other words,&amp;nbsp; since the key is a concatenation of year and state, I want new columns with with the GSP difference for various years for each state.&amp;nbsp; I then intend to do some further analysis.&amp;nbsp; I have found very little information on how to reference a specific row or do this type of thing in EG Filter/Query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There has to be an easy way, and I may have just looked at this too long.&amp;nbsp; Any help is appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 19 Dec 2012 23:14:20 GMT</pubDate>
    <dc:creator>TheoIV</dc:creator>
    <dc:date>2012-12-19T23:14:20Z</dc:date>
    <item>
      <title>Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105032#M9166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am starting to learn SAS EG and using it for my dissertation.&amp;nbsp; I am not sure if I have to run code or if I can do the following in the computed column interface:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THE PROBLEM:&lt;/P&gt;&lt;P&gt;I have a table (STATE) that (to simplify) consists of the following columns: &lt;/P&gt;&lt;P&gt;StateYRKey, State, Year, ChgYr1, ChgYear5, ChgYear10, GSP&amp;nbsp; (e.g.,&amp;nbsp; AK1960, AK, 1960, 1961, 1965, 1970, 123456)&lt;/P&gt;&lt;P&gt;I want to create a computed column for various changes in GSP (again simplifying) Yr1GSPChg, Yr5GSPChg, Yr10GSPChg&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to code something like (or simplier):&lt;/P&gt;&lt;P&gt;For i in {AK..WY} Do&lt;/P&gt;&lt;P&gt;&amp;nbsp; For j = {1960..2012} Do&lt;/P&gt;&lt;P&gt;&amp;nbsp; BEGIN&lt;/P&gt;&lt;P&gt; * The key is a concatenation.&amp;nbsp; I want to access values for specific rows to compute the appropriate difference)&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; STATE.(Concatenate i,j).Yr1GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -1).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; STATE.(Concatenate i,j).Yr5GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -5).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; STATE.(Concatenate i,j).Yr10GSPChg = STATE.(Concatenate i,j)GSP - STATE.(Concatenate i,j -10).GSP&lt;/P&gt;&lt;P&gt;&amp;nbsp; END&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In other words,&amp;nbsp; since the key is a concatenation of year and state, I want new columns with with the GSP difference for various years for each state.&amp;nbsp; I then intend to do some further analysis.&amp;nbsp; I have found very little information on how to reference a specific row or do this type of thing in EG Filter/Query.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There has to be an easy way, and I may have just looked at this too long.&amp;nbsp; Any help is appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Dec 2012 23:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105032#M9166</guid>
      <dc:creator>TheoIV</dc:creator>
      <dc:date>2012-12-19T23:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105033#M9167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There's a simple function to get a row number added as a column, then you can reference that computed column from there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Go to computed columns, advanced expression, type MONOTONIC()&amp;nbsp; just like that.&amp;nbsp; Label and Name your new row number column whatever you want, and you will have a column that lists the row number ascending&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 17:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105033#M9167</guid>
      <dc:creator>sasspan</dc:creator>
      <dc:date>2013-01-03T17:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105034#M9168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to look at lag functions and possibly re-merging the data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data in SAS is processed line by line, not pulled in and reference like a matrix (as you seem to be referring to it).&lt;/P&gt;&lt;P&gt;There are lots of ways around this though, too many to get into here. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 18:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105034#M9168</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-01-03T18:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105035#M9169</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand your objective correctly, here's what I consider the clearest way to do it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, I think it'll be easiest if you restructure your data into a table that has three columns: State, Year, and GSP. So it would look like &lt;/P&gt;&lt;P&gt;this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;State Year GSP&lt;BR /&gt;===== ==== ===&lt;BR /&gt;AK 1960 123456&lt;BR /&gt;...&amp;nbsp; &lt;BR /&gt;FL 1972 234567&lt;BR /&gt;...&amp;nbsp; &lt;BR /&gt;WY 2012 345678&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming 50 states and 53 years, this table will have 2650 records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in Enterprise Guide, the trick is to create a table with your current GSP and the one from the year before.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To do this (assuming your table is named StateData, to ensure we don't confuse the table and the column):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Start a new QueryBuilder dialog on StateData.&lt;/P&gt;&lt;P&gt;2. Click Add Tables, and add StateData a second time. It will be referred to as t2, and your original StateData will be t1. They are actually both the same table. This is a little unusual, but completely legitimate.&lt;/P&gt;&lt;P&gt;3. Click Join Tables. In this dialogue:&lt;BR /&gt;3a. Make sure t1 is joined to t2 on State with an inner join.&lt;BR /&gt;3b. Right click the Join symbol, and click Properties.&lt;BR /&gt;3c. In the Properties window, click Edit... to create a filter for the join.&lt;BR /&gt;3d. In the filter, use the icons or type in the filter value to be t2.year = t1.year - 1.&lt;BR /&gt;3e. Close the Tables and Joins dialoge.&lt;/P&gt;&lt;P&gt;4. On your main query dialogue, select all of the values of t1, and select t2.GSP, renaming it t2.Yr1GSP.&lt;/P&gt;&lt;P&gt;5. Create a new advanced expression, call it Yr1GSPChg, and set it equal to t1.GSP - t2.GSP.&lt;/P&gt;&lt;P&gt;When you run this, it should give you your one year time series. If I were you, I'd add the State and Year from t2 to the results temporarily, and see if everything looks good.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This approach works the same for the 5 and 10 year differences.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;One of the things you'll need to do it figure out what to do about the years that don't have a -1, -5, or -10 year value. There are a number of different approaches you can use.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck!&lt;/P&gt;&lt;P&gt;&amp;nbsp; Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 20:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105035#M9169</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2013-01-03T20:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105036#M9170</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom.... exactly what I want to do!... very helpful.&amp;nbsp; Why didn't I think of that? &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 16:26:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105036#M9170</guid>
      <dc:creator>TheoIV</dc:creator>
      <dc:date>2013-02-13T16:26:46Z</dc:date>
    </item>
    <item>
      <title>Re: Novice Question:  How to Create a Computed Column Based on Row Values</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105037#M9171</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom this helped me too!&amp;nbsp; I am using dates of service and want to know how long it has been since the claims last fill.&amp;nbsp; I am just going to rank the columns and join on claim_id and the rank=rank-1.&amp;nbsp; THANK YOU!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 18:32:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Novice-Question-How-to-Create-a-Computed-Column-Based-on-Row/m-p/105037#M9171</guid>
      <dc:creator>sasspan</dc:creator>
      <dc:date>2013-02-13T18:32:49Z</dc:date>
    </item>
  </channel>
</rss>

