<?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: problem with interpolating quarterly data into monthly data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961581#M374863</link>
    <description>&lt;P&gt;So you need the previous quarter sales to create a curve for the next quarters months?&lt;/P&gt;
&lt;P&gt;But I don't understand what interpollation means here. Aren't the sales figures a sum of sales for each quarter? Wouldn't you then divide each month by three (after creating your curve)...?&lt;/P&gt;
&lt;P&gt;Or does month mean rolling 3 months sales? Then it makes sense.&lt;/P&gt;
&lt;P&gt;Also, didn't understand how you want to manage brands that doesn't exist certain periods. In you result table you have removed Tesla.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, transpose your data so you have one row per brand, year and quarter (this should always be the default structure when storing data).&lt;/P&gt;
&lt;P&gt;Sort by brand, year and quarter.&lt;/P&gt;
&lt;P&gt;You can then use RETAIN in a data step to keep the previous quarters sales when looking at the next record.&lt;/P&gt;
&lt;P&gt;You can keep track on that you are working with the same brand by using BY statement, and use first. and last. logic to assign and calculating values.&lt;/P&gt;
&lt;P&gt;Pseudo code for last step, untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by brand;
   retain prev_qsales;
   if not first.brand then do;
      do m=1 to 3;
         /* your calculation logic goes here */
         month = (quarter - 1) * 3  + m;
         output;
      end;
   end;
   if not last.brand prev_qsales = sales; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Mar 2025 16:03:57 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2025-03-11T16:03:57Z</dc:date>
    <item>
      <title>problem with interpolating quarterly data into monthly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961557#M374860</link>
      <description>&lt;P&gt;Hi SAS-Forum-Members,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a problem with interpolating quarterly data into monthly data.&lt;/P&gt;&lt;P&gt;I have a data that looks like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Car_Brand&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Q1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Q2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Q3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Q4&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Hyundai&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2018&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;130&lt;/TD&gt;&lt;TD&gt;115&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BMW&lt;/TD&gt;&lt;TD&gt;2018&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;130&lt;/TD&gt;&lt;TD&gt;115&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Tesla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&gt;620&lt;/TD&gt;&lt;TD&gt;590&lt;/TD&gt;&lt;TD&gt;620&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;BR /&gt;As you can see there are not always the same Car Brands in every year. The Car Brands can be different every year e.g. when a car_brand is insolvent (usually its the same but in the example Tesla has no sales in 2019, 2020 and so on).&lt;/P&gt;&lt;P&gt;My aim is to interpolate the quarterly data into monthly data. For the first quarter it should look like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Car_Brand&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Jan&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Feb&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Mar&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;Sales_Apr&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Hyundai&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;133,333&lt;/TD&gt;&lt;TD&gt;166,666&lt;/TD&gt;&lt;TD&gt;200&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BMW&lt;/TD&gt;&lt;TD&gt;2019&lt;/TD&gt;&lt;TD&gt;140&lt;/TD&gt;&lt;TD&gt;180&lt;/TD&gt;&lt;TD&gt;220&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Hyundai&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;293,333&lt;/TD&gt;&lt;TD&gt;296,666&lt;/TD&gt;&lt;TD&gt;300&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BMW&lt;/TD&gt;&lt;TD&gt;2020&lt;/TD&gt;&lt;TD&gt;313,333&lt;/TD&gt;&lt;TD&gt;316,666&lt;/TD&gt;&lt;TD&gt;320&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;TD&gt;...&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I need the value of the 4th quarter of 2019 to interpolate the values of January, February and March 2020 and that caused me great difficulties&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you understand what my problem is and can help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot and have a nice day.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 14:46:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961557#M374860</guid>
      <dc:creator>MaxiHösi</dc:creator>
      <dc:date>2025-03-11T14:46:27Z</dc:date>
    </item>
    <item>
      <title>Re: problem with interpolating quarterly data into monthly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961581#M374863</link>
      <description>&lt;P&gt;So you need the previous quarter sales to create a curve for the next quarters months?&lt;/P&gt;
&lt;P&gt;But I don't understand what interpollation means here. Aren't the sales figures a sum of sales for each quarter? Wouldn't you then divide each month by three (after creating your curve)...?&lt;/P&gt;
&lt;P&gt;Or does month mean rolling 3 months sales? Then it makes sense.&lt;/P&gt;
&lt;P&gt;Also, didn't understand how you want to manage brands that doesn't exist certain periods. In you result table you have removed Tesla.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First of all, transpose your data so you have one row per brand, year and quarter (this should always be the default structure when storing data).&lt;/P&gt;
&lt;P&gt;Sort by brand, year and quarter.&lt;/P&gt;
&lt;P&gt;You can then use RETAIN in a data step to keep the previous quarters sales when looking at the next record.&lt;/P&gt;
&lt;P&gt;You can keep track on that you are working with the same brand by using BY statement, and use first. and last. logic to assign and calculating values.&lt;/P&gt;
&lt;P&gt;Pseudo code for last step, untested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   by brand;
   retain prev_qsales;
   if not first.brand then do;
      do m=1 to 3;
         /* your calculation logic goes here */
         month = (quarter - 1) * 3  + m;
         output;
      end;
   end;
   if not last.brand prev_qsales = sales; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Mar 2025 16:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961581#M374863</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-03-11T16:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: problem with interpolating quarterly data into monthly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961617#M374879</link>
      <description>&lt;P&gt;That would be a lot of easy if you have SAS/ETS by using PROC EXPAND.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Car_Brand	$ Year 	Sales_Q1	Sales_Q2	Sales_Q3	Sales_Q4;
cards;
Hyundai	2018 100	130	115	100
BMW	2018	100	130	115	100
Tesla	2018	120	150	135	120
Hyundai	2019	200	260	305	290
BMW	 2019	220	280	325	310
Hyundai	2020 300	600	570	600
BMW	2020	320	620	590	620
;
proc sort data=have out=temp;
by Car_Brand Year;
run;
proc transpose data=temp out=temp2;
by Car_Brand Year;
var Sales_:;
run;
data temp3;
 set temp2; 
 yyq=input(cats(year,scan(_name_,-1,'_')),yyq6.);
 format yyq yymmdd10.;
run;
data temp4;
 merge temp3 temp3(keep=Car_Brand yyq rename=(Car_Brand=_Car_Brand yyq=_yyq) firstobs=2);
 output;
 if Car_Brand=_Car_Brand then do;
   do i=1 to intck('month',yyq,_yyq)-1;
    yyq=intnx('month',yyq,1);
	call missing(col1);
	output;
   end;
 end;
 keep Car_Brand col1 yyq;
run;

proc expand data=temp4 out=want method=join;
by Car_Brand;
convert col1;
id yyq;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1741746008402.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/105357i2D7E4F0093E476CE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1741746008402.png" alt="Ksharp_0-1741746008402.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Mar 2025 02:20:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961617#M374879</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-03-12T02:20:28Z</dc:date>
    </item>
    <item>
      <title>Re: problem with interpolating quarterly data into monthly data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961801#M374932</link>
      <description>&lt;P&gt;Thanks a lot. This code has already helped me a lot. It doesn't quite work, because not always a third is taken (I think that's due to the different days), but it was a good starting point. I don't have much time today, but maybe I can post the code on the weekend like I did. I still have some problems with retain and solved it very cumbersomely.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Mar 2025 17:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/problem-with-interpolating-quarterly-data-into-monthly-data/m-p/961801#M374932</guid>
      <dc:creator>MaxiHösi</dc:creator>
      <dc:date>2025-03-13T17:43:33Z</dc:date>
    </item>
  </channel>
</rss>

