<?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: For each YM, finding Average Amount for each product in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715016#M220815</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355522"&gt;@John04&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Goal is to use the Average value as the "Inline Predicted value" for the next YM; incase it would be for 200401 for product X and Y.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm afraid this doesn't mean anything to me in the context of your original question. Please explain in more detail. And please provide a more representative data set.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jan 2021 15:14:30 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-01-28T15:14:30Z</dc:date>
    <item>
      <title>For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715005#M220807</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find average amount by product_group, product, YM and then using that average for new YM.&lt;/P&gt;&lt;P&gt;for e.g&amp;nbsp;&lt;/P&gt;&lt;P&gt;Until now I tried partition by and indexing but I think it doesn't work in sas.&lt;/P&gt;&lt;P&gt;Hoping that someone can point me in right direction on how to solve this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
input YM Product_Group$ Product$ Amount;
datalines;
200101 X P1 1.2
200201 X P1 8.9
200301 X P1 432.4
200101 Y P2 24.23
200201 Y P2 842.9
200301 Y P2 43.4
run;&lt;/PRE&gt;&lt;P&gt;I want output something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data want;
input YM Product_Group$ Product$ Average;
datalines;
200401 X P1 147.5
200401 Y P1 303.51
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715005#M220807</guid>
      <dc:creator>John04</dc:creator>
      <dc:date>2021-01-28T15:38:51Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715008#M220810</link>
      <description>&lt;P&gt;Why do you need to create an average by product and YM? There is only 1 data point for each product and YM, so the average is just the value of that data point.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Perhaps a more representative example data set would help here.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715008#M220810</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-28T15:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715011#M220811</link>
      <description>&lt;P&gt;First, please test your data step code. It generates missing values for Product and Product_group because you don't have provision for reading character variables.&lt;/P&gt;
&lt;P&gt;I think you meant something more like:&lt;/P&gt;
&lt;PRE&gt;data have;
   input YM Product_Group $ Product $ Amount;
datalines;
200101 X P1 1.2
200101 Y P4 4.3
200102 X P2 2.3
200102 Y P5 4.6
200103 X P3 3.4
200103 Y P6 5.6
200201 X P1 8.9
200201 Y P4 35.6
200202 X P2 53.6
200202 Y P5 24.6
200203 X P3 346.7
200203 Y P6 23.5
200301 X P1 432.4
200301 Y P4 13.5
200302 X P2 1.25
200302 Y P5 32.6
200303 X P3 13.5
200303 Y P6 1236.1
;&lt;/PRE&gt;
&lt;P&gt;You don't say if you want a data set (for further manipulation) or report (people read these). This one way to get a report:&lt;/P&gt;
&lt;PRE&gt;proc means data=have mean;
  class ym product;
  var amount;
run;
 &lt;/PRE&gt;
&lt;P&gt;Means will also create a data set with the OUTPUT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example data is pretty boring for the question as your grouping variables don't show any duplicates so the "mean" is the value in the data.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:09:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715011#M220811</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-28T15:09:02Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715012#M220812</link>
      <description>&lt;P&gt;Are you look for proc means?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means mean;
  class YM Product;
  var Amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By the way, you input statement need to be modified:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;input YM Product_Group$ Product$ Amount;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715012#M220812</guid>
      <dc:creator>whymath</dc:creator>
      <dc:date>2021-01-28T15:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715014#M220813</link>
      <description>Goal is to use the Average value as the "Inline Predicted value" for the next YM; incase it would be for 200401 for product X and Y.</description>
      <pubDate>Thu, 28 Jan 2021 15:10:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715014#M220813</guid>
      <dc:creator>John04</dc:creator>
      <dc:date>2021-01-28T15:10:40Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715016#M220815</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355522"&gt;@John04&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Goal is to use the Average value as the "Inline Predicted value" for the next YM; incase it would be for 200401 for product X and Y.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I'm afraid this doesn't mean anything to me in the context of your original question. Please explain in more detail. And please provide a more representative data set.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715016#M220815</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-28T15:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715025#M220821</link>
      <description>Sorry about that. I changed my data set if that helps.</description>
      <pubDate>Thu, 28 Jan 2021 15:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715025#M220821</guid>
      <dc:creator>John04</dc:creator>
      <dc:date>2021-01-28T15:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715028#M220822</link>
      <description>&lt;P&gt;Again, you haven't provided a meaningful example, you are computing means of ONE data point in each YM/Product combination, which is completely unnecessary, there's no programming involved, the mean of a single data point is that single data point. And then of course the desired output can't be computed from the shown input, as there is no 200401 in the input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please put some effort into creating meaningful and realistic examples of the input data, and output data that is based upon the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Should you really be talking about a situation where you have multiple records for a YM/Product combination, this code will compute the means.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input YM Product_Group Product Amount;
datalines;
200101 X P1 1.2
200201 X P1 8.9
200301 X P1 432.4
200101 Y P2 24.23
200201 Y P2 842.9
200301 Y P2 43.4
run;
proc summary data=have nway;
    class ym product;
    var amount;
    output out=want mean=;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 15:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715028#M220822</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-01-28T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715030#M220824</link>
      <description>I should have specified in more detail. However I changed my dataset if that helps. Thanks</description>
      <pubDate>Thu, 28 Jan 2021 15:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715030#M220824</guid>
      <dc:creator>John04</dc:creator>
      <dc:date>2021-01-28T15:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: For each YM, finding Average Amount for each product</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715055#M220833</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/355522"&gt;@John04&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find average amount by product_group, product, YM and then using that average for new YM.&lt;/P&gt;
&lt;P&gt;for e.g&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Until now I tried partition by and indexing but I think it doesn't work in sas.&lt;/P&gt;
&lt;P&gt;Hoping that someone can point me in right direction on how to solve this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
input YM Product_Group$ Product$ Amount;
datalines;
200101 X P1 1.2
200201 X P1 8.9
200301 X P1 432.4
200101 Y P2 24.23
200201 Y P2 842.9
200301 Y P2 43.4
run;&lt;/PRE&gt;
&lt;P&gt;I want output something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
input YM Product_Group$ Product$ Average;
datalines;
200401 X P1 147.5
200401 Y P1 303.51
run;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is the easiest way I know to get the mean amount by product_group and Product&lt;/P&gt;
&lt;PRE&gt;proc summary data=have nway;
   class  product_group product;
   var amount;
   output out=want (drop=_:) mean=;
run;&lt;/PRE&gt;
&lt;P&gt;But getting a value that does not exist in the source data, ie that 200401, as part of any summary will require further processing, such as data step to add the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Large economy size hint: Instead of using random numbers containing parts of a date, create actual date values with appropriate formats such as:&lt;/P&gt;
&lt;PRE&gt;data have;
input YM :yymmn6. Product_Group$ Product$ Amount;
format ym yymmn.;
datalines;
200101 X P1 1.2
200201 X P1 8.9
200301 X P1 432.4
200101 Y P2 24.23
200201 Y P2 842.9
200301 Y P2 43.4
run;&lt;/PRE&gt;
&lt;P&gt;Then you have all the power of the SAS functions such as INTNX to increment years, such as Intnx('year',ym,1)&amp;nbsp; instead of weird arithmetic like 200101 +100 to simulate a next year. Plus graphs with dates will space tickmarks in nicer intervals. The above would assume the first day of a month for date.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2021 16:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-each-YM-finding-Average-Amount-for-each-product/m-p/715055#M220833</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-28T16:42:05Z</dc:date>
    </item>
  </channel>
</rss>

