<?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: Here the example data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623042#M183331</link>
    <description>&lt;P&gt;Very weird indeed ..&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Especially if it does not even create the "monthly_avg_preyear"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And nothing in the log?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just to 'test' the&amp;nbsp;Proc SQL&amp;nbsp;&lt;/SPAN&gt;left join, please remove the 'a.year-1' and put 'a.year':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table TEST2 as
	select a.*, b.monthly_avg as monthly_avg_preyear
	from TEST as a left join TEST_INT as b
	on a.touchpoint_spec=b.touchpoint_spec and a.month = b.month and a.year=b.year
	order by a.date, a.touchpoint_spec;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Feb 2020 13:14:22 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-02-07T13:14:22Z</dc:date>
    <item>
      <title>New variable with average value per month (+ avg value per month / prev.year)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622135#M182992</link>
      <description>&lt;P&gt;Hello dear experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am kindly asking for your help, since I spent already a lot of time googling and did not find any solution yet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to add a variable to my data set. The variable should be the &lt;STRONG&gt;average of value per month &lt;/STRONG&gt;and the &lt;STRONG&gt;average of value per month previous year&lt;/STRONG&gt;. Please see attached example data: there you can see the desired output variables 'average per month' and 'average per month prev.year')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the following Code I get the needed average per month in a separate table, but I need it as &lt;STRONG&gt;additional variable in the existing data set&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC MEANS Data=mydata;&lt;/P&gt;&lt;P&gt;VAR value;&lt;BR /&gt;Class Date;&lt;BR /&gt;FORMAT Date Monyy.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance for your kind support with this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;SAS Newbie&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:49:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622135#M182992</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-04T07:49:25Z</dc:date>
    </item>
    <item>
      <title>Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622138#M182993</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="example data screenshot.jpg" style="width: 458px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35845iEA1377854B4D8B74/image-size/large?v=v2&amp;amp;px=999" role="button" title="example data screenshot.jpg" alt="example data screenshot.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 07:57:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622138#M182993</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-04T07:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622154#M183004</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an attempt to achieve this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
	input date:DDMMYY10. value;
	datalines;
01.01.2019 0
02.01.2019 100
03.01.2019 -100
04.01.2019 100
05.01.2019 100
01.02.2019 100
02.02.2019 0
03.02.2019 0
04.02.2019 -100
05.02.2019 100
01.01.2020 -100
02.01.2020 0
03.01.2020 0
04.01.2020 -100
05.01.2020 100
;
run;

/* average of value per month */
proc sql;
	create table mydata_temp as
	select date format=monyy., value, avg(value) as monthly_avg
	from mydata
	group by year(date), month(date)
	order by month(date), day(date), year(date);
run;

/* average of value per month previous year */

data want;
	set mydata_temp;
	monthly_avg_preyear = lag(monthly_avg);
	if lag(date) &amp;gt; date or year(lag(date)) = year(date) then call missing(monthly_avg_preyear);
run;
proc sort data=want;
	by date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-02-04 à 09.59.41.png" style="width: 357px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35847i8F4054D686820A61/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-02-04 à 09.59.41.png" alt="Capture d’écran 2020-02-04 à 09.59.41.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Feb 2020 09:00:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622154#M183004</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-04T09:00:06Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622434#M183090</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;Wow thank you so much for your prompt reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked for my dataset! However I have already come across another issue..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the average to be calculated for different groups. I tried to do it with "WHERE" statement, but I want the other data to remain in the data set as well [more like if ... then do avg(value) else .]?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE mydata_temp AS 
   SELECT Touchpoint, Unit, Date format=monyy.,
	      avg(NPS_value) as monthly_avg_claimsnl
   FROM mydata
   WHERE Unit = 'N' AND Touchpoint = '1'
      group by year(date), month(date)
	  order by month(date), day(date), year(date);
QUIT;

PROC SQL;
   CREATE TABLE mydata_temp AS 
   SELECT Touchpoint, Unit, Date format=monyy.,
	      avg(NPS_value) as monthly_avg_claimsnl
   FROM mydata
   WHERE Unit = 'F' AND Touchpoint = '2'
      group by year(date), month(date)
	  order by month(date), day(date), year(date);
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;attached I tried to show the preffered output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="test data.jpg" style="width: 500px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35872iB9FA279EC743BAE2/image-size/large?v=v2&amp;amp;px=999" role="button" title="test data.jpg" alt="test data.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 13:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622434#M183090</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-05T13:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622460#M183107</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sounds great!&lt;/P&gt;
&lt;P&gt;Here is the revised code to meet the new requirement.&lt;/P&gt;
&lt;P&gt;Please test it on you data and let me know.&lt;/P&gt;
&lt;P&gt;I am just a bit confused about the values displayed in the Excel file for the monthly_avg variable: for example, I agree with -33.33 for the group (unit=N touchpoint=1) in 2020. However, it should be 25 instead of 100 in 2019?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata;
	input date:MMDDYY10. unit $ touchpoint value;
	datalines;
1/1/2019 F 1 0
1/2/2019 F 1 100
1/3/2019 F 2 -100
1/4/2019 F 2 100
1/5/2019 N 2 100
1/6/2019 N 1 0
1/7/2019 N 1 100
1/8/2019 N 1 -100
1/9/2019 N 1 100
1/1/2020 F 1 -100
1/2/2020 F 1 0
1/3/2020 F 2 0
1/4/2020 F 2 -100
1/5/2020 F 1 100
1/1/2020 N 1 -100
1/2/2020 N 2 0
1/3/2020 N 2 0
1/4/2020 N 1 -100
1/5/2020 N 1 100
;
run;

/* average of value per month */

proc sql;
	create table mydata_temp as
	select date format=MMDDYY10.,
		   year(date) as year, month(date) as month,
		   unit, touchpoint,
		   avg(value) as monthly_avg
	from mydata
	group by unit, touchpoint, month(date), year(date);
run;

/* average of value per month previous year */

proc sql;
	create table want as
	select distinct a.*, b.monthly_avg as monthly_avg_preyear
	from mydata_temp as a left join mydata_temp as b
	on a.unit=b.unit and a.touchpoint=b.touchpoint
	   and a.month = b.month and (a.year-1)=b.year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Feb 2020 14:27:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/622460#M183107</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-05T14:27:45Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623003#M183317</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The monthly avg part worked perfectly and the join as well, but I don't get any data for the variable monthly_avg_preyear...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have an idea about what could be the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Oh and about the calculation difference, you are right, that was a 'typo' from my end. Sorry about the confusion.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Best&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 10:51:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623003#M183317</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T10:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623009#M183319</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I get when I run the code.&lt;/P&gt;
&lt;P&gt;Could you please share a portion of your SAS log?&lt;/P&gt;
&lt;P&gt;Are the sample data representative from your 'real' data?&lt;/P&gt;
&lt;P&gt;Is there a confusion in the date format (e.g DDMMYY10. or MMDDYY10.) ?&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="Capture d’écran 2020-02-07 à 12.03.57.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35923iBEB87980E12B0871/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-02-07 à 12.03.57.png" alt="Capture d’écran 2020-02-07 à 12.03.57.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 11:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623009#M183319</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T11:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623017#M183321</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did run it with my real data, which is more or less the same (except there are a lot more variables included). Here the log summary as a screenshot:&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Logsummary.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35924i72136537C538B44B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Logsummary.jpg" alt="Logsummary.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The programm runs through, but if I filter for ["monthly_avg_preyear" NOT .] there are no entrys.&lt;/P&gt;&lt;P&gt;The date format looks fine to me. "month" and "year" have been correctly allocated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here some example output:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="example output.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35926i641598D413D1B272/image-size/large?v=v2&amp;amp;px=999" role="button" title="example output.jpg" alt="example output.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To make things more easy I created a new variable "Touchpoint_spec" which already shows the groups build (in example F2, N1). I also created the variable preyear. Maybe we could write something like [IF Date = Date_preyear Put monthly_avg] ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your support.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 11:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623017#M183321</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T11:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623019#M183322</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is a good idea to create a variable contatening unit and touchpoint -&amp;gt; it will simplify the code.&lt;/P&gt;
&lt;P&gt;i am a bit concerned by the warning in the log, specifying that the date is already in the dataset. Does it still appear if you do that for the first step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/* average of value per month */

proc sql;
	create table mydata_temp as
	select *,
		   year(date) as year,
		   month(date) as month,
		   avg(value) as monthly_avg
	from mydata
	group by touchpoint_spec, month(date), year(date);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 12:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623019#M183322</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T12:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623024#M183324</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Excellent! The warning disappeared and I have all my variables in the file!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I seem to make a mistake, because I cannot find monthly_avg_preyear&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="no_preyear.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35927i72B36402CC821C6C/image-size/large?v=v2&amp;amp;px=999" role="button" title="no_preyear.jpg" alt="no_preyear.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you see what went wrong in the code?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE TMP.TEST AS 
	select *,
		   year(date) as year,
		   month(date) as month,
		   avg(NPS_value) as monthly_avg
	from TMP.SAS_ZUM_TABLEAU_AKTUALISIEREN
	group by Touchpoint_spec, month(date), year(date);
run;

/* average of value per month previous year */
proc sql;
	create table TMP.TEST2 as
	select distinct a.*, b.monthly_avg as monthly_avg_preyear
	from TMP.TEST as a left join TMP.TEST as b
	on a.Touchpoint_spec=b.Touchpoint_spec and a.Date=b.Date
	   and a.month = b.month and (a.year-1)=b.year;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 12:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623024#M183324</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T12:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623030#M183326</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am wondering if the issue come from the 'distinct' keyword.&lt;/P&gt;
&lt;P&gt;Could you please try this ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table TMP.TEST as
	select *,
		   year(date) as year,
		   month(date) as month,
		   avg(NPS_value) as monthly_avg
	from TMP.SAS_ZUM_TABLEAU_AKTUALISIEREN
	group by touchpoint_spec, month(date), year(date);
run;

/* average of value per month previous year */

proc sql;
	create table TMP.TEST_INT as
	select distinct touchpoint_spec, year, month, monthly_avg
	from TMP.TEST;
quit;

proc sql;
	create table TMP.TEST2 as
	select a.*, b.monthly_avg as monthly_avg_preyear
	from TMP.TEST as a left join TMP.TEST_INT as b
	on a.touchpoint_spec=b.touchpoint_spec and a.month = b.month and (a.year-1)=b.year
	order by a.date, a.touchpoint_spec;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 12:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623030#M183326</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T12:42:27Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623034#M183327</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Its bizarre. It does still not even create the variable "monthly_avg_preyear"..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 12:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623034#M183327</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T12:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623042#M183331</link>
      <description>&lt;P&gt;Very weird indeed ..&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Especially if it does not even create the "monthly_avg_preyear"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;And nothing in the log?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Just to 'test' the&amp;nbsp;Proc SQL&amp;nbsp;&lt;/SPAN&gt;left join, please remove the 'a.year-1' and put 'a.year':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table TEST2 as
	select a.*, b.monthly_avg as monthly_avg_preyear
	from TEST as a left join TEST_INT as b
	on a.touchpoint_spec=b.touchpoint_spec and a.month = b.month and a.year=b.year
	order by a.date, a.touchpoint_spec;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 13:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623042#M183331</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T13:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623052#M183335</link>
      <description>&lt;P&gt;Ok. now i get the Error Message "ERROR: COLUMN DATE COULD NOT BE FOUND IN THE TABLE/VIEW IDENTIFIED WITH THE CORRELATION NAME A."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;referring to :&amp;nbsp;order by a.date, a.touchpoint_spec;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 14:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623052#M183335</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T14:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623054#M183336</link>
      <description>&lt;P&gt;I removed a.Date from ORDER BY and it worked!! Even with the lost monthly_avg_preyear&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="worked.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/35929iDC5D861C776F89E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="worked.jpg" alt="worked.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a possibility I could get all my other variables in there too?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	proc sql;
	create table TMP.SAS_Zum_Tableau_aktualisieren as
	select *,
		   year(date) as year,
		   month(date) as month,
		   avg(NPS_value) as monthly_avg
	from TMP.SAS_ZUM_TABLEAU_AKTUALISIEREN
	group by touchpoint_spec, month(date), year(date);
run;

/* average of value per month previous year */

proc sql;
	create table TMP.SAS_Zum_Tableau_aktualisieren as
	select distinct touchpoint_spec, year, month, monthly_avg
	from TMP.SAS_Zum_Tableau_aktualisieren;
quit;

proc sql;
	create table TMP.SAS_Zum_Tableau_aktualisieren as
	select a.*, b.monthly_avg as monthly_avg_preyear
	from TMP.SAS_Zum_Tableau_aktualisieren as a left join TMP.SAS_Zum_Tableau_aktualisieren as b
	on a.touchpoint_spec=b.touchpoint_spec and a.month = b.month and (a.year-1)=b.year
	order by a.touchpoint_spec;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Feb 2020 14:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623054#M183336</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T14:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623055#M183339</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No panic, we are almost there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;It comes from the fact that you use the same name for all your tables:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;create table &lt;FONT color="#339966"&gt;TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;BIS&lt;/U&gt;&lt;/FONT&gt;&amp;nbsp;as&lt;/DIV&gt;
&lt;DIV&gt;select *,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; year(date) as year,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; month(date) as month,&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp; avg(NPS_value) as monthly_avg&lt;/DIV&gt;
&lt;DIV&gt;from &lt;FONT color="#3366FF"&gt;TMP.SAS_ZUM_TABLEAU_AKTUALISIEREN&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;group by touchpoint_spec, month(date), year(date);&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;/* average of value per month previous year */&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;create table &lt;FONT color="#FF00FF"&gt;TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;TER&lt;/U&gt;&lt;/FONT&gt; as&lt;/DIV&gt;
&lt;DIV&gt;select distinct touchpoint_spec, year, month, monthly_avg&lt;/DIV&gt;
&lt;DIV&gt;from&lt;FONT color="#339966"&gt; TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;BIS&lt;/U&gt;;&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;create table&lt;FONT color="#FF0000"&gt; TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;WANT&lt;/U&gt; &lt;/FONT&gt;as&lt;/DIV&gt;
&lt;DIV&gt;select a.*, b.monthly_avg as monthly_avg_preyear&lt;/DIV&gt;
&lt;DIV&gt;from&lt;FONT color="#339966"&gt; TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;BIS&lt;/U&gt;&lt;/FONT&gt; as a left join &lt;FONT color="#FF00FF"&gt;TMP.SAS_Zum_Tableau_aktualisieren&lt;U&gt;TER&lt;/U&gt;&lt;/FONT&gt; as b&lt;/DIV&gt;
&lt;DIV&gt;on a.touchpoint_spec=b.touchpoint_spec and a.month = b.month and (a.year-1)=b.year&lt;/DIV&gt;
&lt;DIV&gt;order by a.touchpoint_spec;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Fri, 07 Feb 2020 14:17:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623055#M183339</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T14:17:00Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623065#M183346</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much! I really appreciate your great support with this!!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a lovely weekend.&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Gretaku&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 15:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623065#M183346</guid>
      <dc:creator>Gretaku</dc:creator>
      <dc:date>2020-02-07T15:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Here the example data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623087#M183358</link>
      <description>&lt;P&gt;Awesome!&lt;/P&gt;
&lt;P&gt;Thank you for your patience&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/310423"&gt;@Gretaku&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a lovely weekend too&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 15:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/New-variable-with-average-value-per-month-avg-value-per-month/m-p/623087#M183358</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T15:50:27Z</dc:date>
    </item>
  </channel>
</rss>

