<?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 perform calculation on every nth observation within an array? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467152#M119236</link>
    <description>&lt;P&gt;So I've reviewed the original requirements and I misinterpreted the requirements. Ultimately I do need to combine the month output with the yearly average output, but the month output actually needs to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ideal.PNG" style="width: 425px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20977iD96F762AA3706164/image-size/large?v=v2&amp;amp;px=999" role="button" title="ideal.PNG" alt="ideal.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So technically I'm not calculating an average for the month output. I'm confused about how to get this from the original dataset though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 Jun 2018 19:35:25 GMT</pubDate>
    <dc:creator>Errant</dc:creator>
    <dc:date>2018-06-02T19:35:25Z</dc:date>
    <item>
      <title>How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467054#M119202</link>
      <description>&lt;P&gt;I have a data set that breaks down the monthly average price of three products over the course of 10 years.&amp;nbsp; I need to represent the yearly average price for each of the three products, so I essentially to take the overall average of every 12 observations for 396+ observations. I'm trying to write an array that will do this. I know that there's something very off structurally, but I'm having a hard time seeing it myself. I've created three variables (gas_yearly etc.) but I've hit a dead end when it comes to writing the looping statement to average every 12 observations.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
set qfour.aveprices;
input gas_yearly milk_yearly eggs_yeary;
array avg(3)gas_yearly milk_yearly eggs_yeary;
	 do i=1 to dim(avg);
	 *a statement that represents the overall average of every 12 observations&lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;-e&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jun 2018 23:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467054#M119202</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-01T23:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467056#M119203</link>
      <description>&lt;P&gt;So here's the problem. Arrays work on variables, going across the rows, and not down a column, which seems to be what you are describing. Thus, as you have explained the problem, arrays will not work (or you have explained it in such a way that I'm not understanding the problem).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you want to find the means of every sequence of 12 observations, here is how to do this. Create an index indicating which group of 12 observations each observation is in. This assumes that there is no variable indicating YEAR that is already in the data set. (And if there is not, then there should be). Then run PROC SUMMARY on this index variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
    set qfour.aveprices;
    group_of_twelve=floor((_n_-1)/12);
run;

Proc summary data=want;
    class group_of_twelve;
    var gas_yearly milk_yearly eggs_yeary; 
    /* That's your spelling error, not mine */
    output out=final mean=;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 00:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467056#M119203</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-02T00:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467057#M119204</link>
      <description>&lt;P&gt;Why don't you add a date column to your data to record the date of the measurements? It will make your analyses so much easier.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 00:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467057#M119204</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2018-06-02T00:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467062#M119206</link>
      <description>&lt;P&gt;Can you explain your data structure and provide some sample data, fake data is fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens if your data is sorted? Can you sort the data to not take the 12th row and instead group things together more logically?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 01:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467062#M119206</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-02T01:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467076#M119211</link>
      <description>&lt;P&gt;I've been issues sorting the data with two conditions. Here's a snippet of the original:&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="gas_shot.PNG" style="width: 309px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20967iD6C571EB5BDD5487/image-size/large?v=v2&amp;amp;px=999" role="button" title="gas_shot.PNG" alt="gas_shot.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It goes from the years 2004-2014 for each product. Everything is already sorted, I'm having issues grouping and subsetting.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;this code works:
proc print data = qfour.aveprices;
where year = 2004;run; 

this code does not for some reason.
proc print data = qfour.aveprices;
where year = 2004 and commodity = 'gas';run;&lt;BR /&gt;&lt;BR /&gt;this also doesn't work&lt;/PRE&gt;&lt;PRE&gt;proc print data = qfour.aveprices;
where commodity = 'gas';&lt;/PRE&gt;&lt;PRE&gt;I get this response: NOTE: No observations were selected from data set QFOUR.AVEPRICES. NOTE: There were 0 observations read from the data set QFOUR.AVEPRICES. WHERE (commodity='gas');&lt;/PRE&gt;&lt;P&gt;I think I need to create a dataset for each product and then perhaps I can create a variable that calculates the average of every 12 obs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also trying to do the normal data step, where I create an output hasn't worked either.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;  DATA sample_small;
  SET test.aveprices;
     IF year = 2014;
     If commodity = gas;
     RUN;
Proc print sample_small;run;
NOTE: Variable gas is uninitialized.
NOTE: There were 396 observations read from the data set TEST.AVEPRICES.
NOTE: The data set WORK.SAMPLE_SMALL has 0 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.23 seconds
      cpu time            0.21 seconds


2614  proc print data= sample_small;run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jun 2018 03:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467076#M119211</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T03:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467080#M119212</link>
      <description>It’s Gas, capital G. &lt;BR /&gt;&lt;BR /&gt;Try the following, see the want data set that gets created. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Proc means data=have;&lt;BR /&gt;Class year commodity;&lt;BR /&gt;Var price;&lt;BR /&gt;Output out =want mean= avg_price;&lt;BR /&gt;Run;</description>
      <pubDate>Sat, 02 Jun 2018 04:23:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467080#M119212</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-02T04:23:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467094#M119216</link>
      <description>&lt;P&gt;Not quite sure if this is what you want to do, but if you want the rolling average of the last 12 observations, it can be done something like this:&lt;/P&gt;&lt;PRE&gt;data want;
  set qfour.aveprices;
  array a_gas (0:11) 8 _temporary_;&lt;BR /&gt;  array a_milk (0:11) 8 _temporary_;&lt;BR /&gt;  array a_eggs (0:11) 8 _temporary_;&lt;BR /&gt;  _N_=mod(_N_,12); /* array index */&lt;BR /&gt;  a_gas(_N_)=gas;&lt;BR /&gt;  a_milk(_N_)=milk;&lt;BR /&gt;  a_eggs(_N_)=eggs;&lt;BR /&gt;  gas_mean=mean(of a_gas(*));&lt;BR /&gt;  milk_mean=mean(of a_milk(*));&lt;BR /&gt;  eggs_mean=mean(of a_eggs(*));&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Note the use of zero-based arrays (the 0:11construct). They make the code simpler (array index is simply mod(_N_,12)) and execute slightly faster (simpler calculation of address offset).&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 07:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467094#M119216</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-06-02T07:22:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467098#M119218</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;For the special case here where we've got already the month variable AND assuming there are no missing months, below could work as well.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length Year Month 8 Commodity $4 Price 8;
  do commodity='Gas ', 'Milk', 'Eggs';
    do year=2004 to 2014;
      do month=1 to 12;
        price+2;
        output;
      end;
    end;
  end;
  stop;
run;

proc sort data=have;
  by Commodity year month;
run;

data want;
  set have;
  by Commodity year month;
  array _price {12} _temporary_;
  if first.commodity then
    do;
      call missing(of _price[*]);
    end;
  _price[month]=price;
  price_avg=mean(of _price{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Jun 2018 08:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467098#M119218</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-06-02T08:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467107#M119224</link>
      <description>&lt;P&gt;Now that we've seen the data, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; has come up with the simplest and most straight forward solution, use PROC MEANS/PROC SUMMARY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess I don't understand why people are using a data step to solve this problem of finding an average of these data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212633"&gt;@Errant&lt;/a&gt;, who said:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I think I need to create a dataset for each product and then perhaps I can create a variable that calculates the average of every 12 obs.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No you don't need any of this. One dataset will work, then run PROC MEANS/PROC SUMMARY on the data, shown in the reply above by Reeza.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 11:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467107#M119224</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-02T11:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467122#M119225</link>
      <description>&lt;P&gt;thank you, that worked! I winded up using that code to create two outputs, one that shows the yearly average for product and the other that shows the overall average for commodities. I need to merge these two datasets, to show the yearly and monthly average per product, but I don't have a unique identifier, the only thing I have is commodity, and sort and merging by commodity doesn't seem to work. Do you know if there's a way to get around only having 2 classes in a class statement?&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 13:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467122#M119225</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T13:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467123#M119226</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212633"&gt;@Errant&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thank you, that worked! I winded up using that code to create two outputs, one that shows the yearly average for product and the other that shows the overall average for commodities. I need to merge these two datasets, to show the yearly and monthly average per product, but I don't have a unique identifier, the only thing I have is commodity, and sort and merging by commodity doesn't seem to work. Do you know if there's a way to get around only having 2 classes in a class statement?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There's really no way for me to advise you, unless you show us what you are talking about, and show us what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can have as many variables in a CLASS statement as you want.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 13:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467123#M119226</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-02T13:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467128#M119228</link>
      <description>&lt;P&gt;So at this point in&amp;nbsp; time I have two outputs.&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="mnth_shot.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20971iC5C8C7EAE2D92ED5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mnth_shot.PNG" alt="mnth_shot.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="yr_shot.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20972i083703A8DA4BA451/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yr_shot.PNG" alt="yr_shot.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I essentially want an output that expresses the product average for both month and year, by utilizing these outputs. However, I'm confused about how to sort/merge it. And the class statement runs with three classes, but it only produces one average, which makes me that maybe it only works on one dependent variable (avg_price in this case)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I tried.&lt;/P&gt;&lt;PRE&gt;Proc means data=qfour.aveprices;
Class year commodity;
Var price;
Output out =want mean= avg_price;
Run;

proc means data = qfour.aveprices;
Class month commodity;
var price;
output out = want2 mean =avg_price; run; 
&lt;BR /&gt;*following only produces one average;
proc means data = qfour.aveprices;
Class month year commodity;
var price;
output out = want3 mean =avg_price; run; &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I need to create two separate variables, one that represents yearly average and the other that represents monthly average.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 14:07:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467128#M119228</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T14:07:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467132#M119229</link>
      <description>&lt;P&gt;You have two separate data sets. I see that. Now explain them, what are they? How do you want to combine them? Show us, type in a portion of what you would like to see when you combine these two data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;I essentially want an output that expresses the product average for both month and year, by utilizing these outputs.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the first time you have mentioned that you want an average BY MONTH. Explain further where this month average would come from given your original data that you showed.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 15:36:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467132#M119229</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-02T15:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467135#M119230</link>
      <description>&lt;P&gt;Sorry about the confusion, the monthly calculation was just the next calculation that I needed to complete after getting the yearIy average. After getting both of those in two separate outputs, I wanted to merge them, to get a table that shows the the product name, the yearly average and the monthly average,&amp;nbsp;essentially&amp;nbsp;combining&amp;nbsp;the averages from both outputs.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At this point, I've tried sorting each output by commodity name (seemed like the closest thing to an identifier in both outputs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this code to sort&lt;/P&gt;&lt;PRE&gt;data sorta;
set want;
by commodity;run;
proc print data = sorta;run;
&lt;BR /&gt;*and then for the second output
data sortb;
set want2;
by commodity;run;
proc print data = sortb;run;&lt;/PRE&gt;&lt;P&gt;I get the same output for both commands for some reason. And it doesn't state any errors, but as you can see it's missing data. Which is messing up the merge process.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="eggs.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20973i04CB3D86A80EB258/image-size/medium?v=v2&amp;amp;px=400" role="button" title="eggs.PNG" alt="eggs.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Ultimately, I would like a data set that looks like the one above with the commodity and the average price for year and month.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 16:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467135#M119230</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T16:18:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467144#M119234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/212633"&gt;@Errant&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry about the confusion, the monthly calculation was just the next calculation that I needed to complete after getting the yearIy average. After getting both of those in two separate outputs, I wanted to merge them, to get a table that shows the the product name, the yearly average and the monthly average,&amp;nbsp;essentially&amp;nbsp;combining&amp;nbsp;the averages from both outputs.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I don't think you really want to "merge" the two data sets ... not MERGE in the sense of the SAS data step command MERGE. Or maybe you do mean "merge", but I can't imagine what that table would look like. Please show us an example (type it in yourself) of what the merged table looks like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also don't know what final result of all this analysis should be, after you do the merge somehow, then what? Please show us. There may be very simple ways to get there, we might be able to figure that out, if only you told us what final analysis should look like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think we need to temporarily stop talking about SAS code, and talk about EXACTLY what output you need and where you are going, and the only way to do that is for you to show us what you want.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 18:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467144#M119234</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-06-02T18:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467152#M119236</link>
      <description>&lt;P&gt;So I've reviewed the original requirements and I misinterpreted the requirements. Ultimately I do need to combine the month output with the yearly average output, but the month output actually needs to look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ideal.PNG" style="width: 425px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/20977iD96F762AA3706164/image-size/large?v=v2&amp;amp;px=999" role="button" title="ideal.PNG" alt="ideal.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So technically I'm not calculating an average for the month output. I'm confused about how to get this from the original dataset though.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 19:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467152#M119236</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T19:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467157#M119238</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
*Sort by month/year;
proc sort data=have;
by month year;
run;

*calculate summary statistics by month;
proc means data=have nway;
by month;
var gas milk eggs;
output out=monthly_averages mean(gas)= avg_gas mean(milk) = avg_milk mean(eggs)=avg_eggs;
run;

*merge results back into original dataset by month;
data want;
merge have monthly_averages;
by month;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you post data as text instead of image that would be helpful. We can't write a program off an image, unless we type it out and I'm too lazy for that. This will calculate monthly averages across all years, if you only need certain years, you can use a WHERE statement to filter the years. Then it merges it back to the original data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 20:01:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467157#M119238</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-02T20:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467158#M119239</link>
      <description>&lt;P&gt;There a lot of observations, but I can upload the datafile.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Jun 2018 20:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467158#M119239</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-02T20:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467183#M119252</link>
      <description>&lt;P&gt;Did the code provided work? If there’s an issue I’ll take another look but it should work. If it doesn’t include your code, log and a description of the issue.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 00:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467183#M119252</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-03T00:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform calculation on every nth observation within an array?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467185#M119254</link>
      <description>&lt;P&gt;I actually had to switch gears for a couple hours, but I'm going get back to that specific problem. I'll definitely keep you updated, thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 03 Jun 2018 01:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-perform-calculation-on-every-nth-observation-within-an/m-p/467185#M119254</guid>
      <dc:creator>Errant</dc:creator>
      <dc:date>2018-06-03T01:00:19Z</dc:date>
    </item>
  </channel>
</rss>

