<?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: Adding a computed column to a data set based on the last 2 columns that are dynamically named, in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450862#M113581</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202675"&gt;@SasDewd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this possible to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;Yes it is.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you need to know how?&amp;nbsp; These are the steps I'd take:&lt;/P&gt;
&lt;P&gt;1. Add a prefix to your Transpose so your columns have a standard prefix and you can short cut reference&amp;nbsp;your variable list&lt;/P&gt;
&lt;P&gt;2. Change your dates so that you can be assured they'll be in the correct order. I don't think you can with Date9 format, try YYMMDD for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. In a data step create an array, using the PREFIX to list the variables&lt;/P&gt;
&lt;P&gt;4. Use DIM() to get the number of items. Now you have the dimension and can easily reference the last and second last.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you mention computed column, I'm going to assume you're using EG. AFAIK there isn't an easy way to do this via the GUI but it's relatively easy to program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 03 Apr 2018 20:09:51 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-04-03T20:09:51Z</dc:date>
    <item>
      <title>Adding a computed column to a data set based on the last 2 columns that are dynamically named,</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450819#M113572</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to SAS and this may or may not be simple but I spent a couple of days and cannot figure it out.&lt;/P&gt;&lt;P&gt;I have a data set that I got through PROC SQL and TRANSPOSE and some other data manipulation procedures.&lt;/P&gt;&lt;P&gt;It has several columns that depend on the date the project is run on.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, if run today it'll have columns named 31Mar2018, 01APR2018, and 02APR2018 (let's say-it'll have more than 3 columns but this is the idea).&lt;/P&gt;&lt;P&gt;I need to add another column that will look at the last 2 columns 1st and 2nd APR and compare the values and display the change (for example 27% as in 27% increase in sales).&lt;/P&gt;&lt;P&gt;Is this possible to do?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 19:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450819#M113572</guid>
      <dc:creator>SasDewd</dc:creator>
      <dc:date>2018-04-03T19:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a computed column to a data set based on the last 2 columns that are dynamically named,</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450852#M113579</link>
      <description>&lt;P&gt;You created this nightmare by transposing the data.&amp;nbsp; The previous form was an excellent format for programming.&amp;nbsp; Just go back to the data at&amp;nbsp;that&amp;nbsp; point, and program with the untransposed data.&amp;nbsp; The only reason to transpose the data would be if the final reporting procedure you are using doesn't know how to do that on its own.&amp;nbsp; Otherwise, it should never be transposed in that way.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 19:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450852#M113579</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-03T19:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a computed column to a data set based on the last 2 columns that are dynamically named,</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450862#M113581</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202675"&gt;@SasDewd&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this possible to do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;Yes it is.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you need to know how?&amp;nbsp; These are the steps I'd take:&lt;/P&gt;
&lt;P&gt;1. Add a prefix to your Transpose so your columns have a standard prefix and you can short cut reference&amp;nbsp;your variable list&lt;/P&gt;
&lt;P&gt;2. Change your dates so that you can be assured they'll be in the correct order. I don't think you can with Date9 format, try YYMMDD for example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. In a data step create an array, using the PREFIX to list the variables&lt;/P&gt;
&lt;P&gt;4. Use DIM() to get the number of items. Now you have the dimension and can easily reference the last and second last.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you mention computed column, I'm going to assume you're using EG. AFAIK there isn't an easy way to do this via the GUI but it's relatively easy to program.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good Luck.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 20:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450862#M113581</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-03T20:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a computed column to a data set based on the last 2 columns that are dynamically named,</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450887#M113589</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;&lt;P&gt;You might be right, Astounding, transpose did complicate it but I need to replicate an existing report and so I don't have much say in how it's displayed. Also, that last column was requested after I thought I had everything done, the way I wanted it.&lt;/P&gt;&lt;P&gt;I still think the biggest problem is the names of columns that are dynamically assigned so cannot be hardcoded.&lt;/P&gt;&lt;P&gt;I'll try to do it the way you suggested, Reeza.&lt;/P&gt;&lt;P&gt;It makes perfect sense but, like I said, I'm new to SAS so hopefully I can figure it out.&lt;/P&gt;&lt;P&gt;I completed the first 2 steps already so now I just need to figure out the other 2 - the array and logic to create a new, computed, column.&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Tue, 03 Apr 2018 20:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-computed-column-to-a-data-set-based-on-the-last-2/m-p/450887#M113589</guid>
      <dc:creator>SasDewd</dc:creator>
      <dc:date>2018-04-03T20:55:41Z</dc:date>
    </item>
  </channel>
</rss>

