<?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 Trends analysis Calculation Programming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447182#M112274</link>
    <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling to write a program for trend analysis, below is screenshot of what I am trying to accomplish&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="Excel.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19340i27A0CCF20421EDED/image-size/large?v=v2&amp;amp;px=999" role="button" title="Excel.png" alt="Excel.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have Adjusted_PMPM value for three years (2015,2016, 2017). I have to find the Expected 1 and Expected 2 column values using the formula:&amp;nbsp; Adjusted_PMPM*(1+R), Where, R is 7%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Value of R is constant for the entire calculation, it's the Adjusted_PMPM which changes.&lt;/P&gt;&lt;P&gt;For Expected_1, start from 2015:&lt;/P&gt;&lt;P&gt;For Expected_1 value for 2016, it will be : 3304.55*(1+0.07) = 3545.55&lt;/P&gt;&lt;P&gt;but then Expected_1 value for 2017 will be 3545.55*(1+0.07) = 3804.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then again for Expected_2 value, we will start from 2016&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Excel2.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19343i396ABED18675980E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Excel2.png" alt="Excel2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So Expected_2 value for 2017 will be 3145.41*(1+0.07) = 3374.80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And finally, Average the two expected values for 2017 to get the final value in the last column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attaching the&amp;nbsp;Excel sheet, if in case that helps in the process.&lt;/P&gt;&lt;P&gt;I tried adding the SAS dataset, it won't let me add the dataset here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Mar 2018 15:54:44 GMT</pubDate>
    <dc:creator>Abhi_Garg</dc:creator>
    <dc:date>2018-03-20T15:54:44Z</dc:date>
    <item>
      <title>Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447182#M112274</link>
      <description>&lt;P&gt;Hi Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struggling to write a program for trend analysis, below is screenshot of what I am trying to accomplish&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="Excel.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19340i27A0CCF20421EDED/image-size/large?v=v2&amp;amp;px=999" role="button" title="Excel.png" alt="Excel.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have Adjusted_PMPM value for three years (2015,2016, 2017). I have to find the Expected 1 and Expected 2 column values using the formula:&amp;nbsp; Adjusted_PMPM*(1+R), Where, R is 7%.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Value of R is constant for the entire calculation, it's the Adjusted_PMPM which changes.&lt;/P&gt;&lt;P&gt;For Expected_1, start from 2015:&lt;/P&gt;&lt;P&gt;For Expected_1 value for 2016, it will be : 3304.55*(1+0.07) = 3545.55&lt;/P&gt;&lt;P&gt;but then Expected_1 value for 2017 will be 3545.55*(1+0.07) = 3804.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then again for Expected_2 value, we will start from 2016&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Excel2.png" style="width: 412px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19343i396ABED18675980E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Excel2.png" alt="Excel2.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;So Expected_2 value for 2017 will be 3145.41*(1+0.07) = 3374.80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And finally, Average the two expected values for 2017 to get the final value in the last column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attaching the&amp;nbsp;Excel sheet, if in case that helps in the process.&lt;/P&gt;&lt;P&gt;I tried adding the SAS dataset, it won't let me add the dataset here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will be much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 15:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447182#M112274</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T15:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447191#M112277</link>
      <description>&lt;P&gt;I have done it this far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If someone can help me improvise this, I'll be grateful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test (keep=Prod_type Calendar_year Adjusted_PMPM Trend Expected_1 Expected_2);
	obs1 = 1;
		do while (obs1 &amp;lt; = nobs);
		set Non_engaged NOBS=nobs;
		by prod_type;
		obs2= obs1-1;
		set Non_engaged (rename=(Prod_type = Prod_type_1
											  Calendar_year = Calendar_year_1
											  adjusted_PMPM = adjusted_PMPM_1
											   trend = trend_1)) point=obs2;
		Expected_1 = adjusted_PMPM_1*(1+trend);

		obs3= obs2-1;
		set Non_engaged (rename=(Prod_type = Prod_type_2
											  Calendar_year = Calendar_year_2
											  adjusted_PMPM = adjusted_PMPM_2
											   trend = trend_2)) point=obs3;
		Expected_1x = adjusted_PMPM_2*(1+trend);
		Expected_2 = Expected_1x*(1+trend);

	obs1 + 1;
	output;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 16:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447191#M112277</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T16:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447192#M112278</link>
      <description>&lt;P&gt;Post your data as text, specifically what your input data will look like.&lt;/P&gt;
&lt;P&gt;Exactly what you're starting with is helpful. Your solution appears overcomplicated at this point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And will you have only two years or does this need to be generalized across multiple records.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 16:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447192#M112278</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-20T16:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447194#M112279</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is the text format dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes, data will only have three years span. At least&amp;nbsp;for remaining&amp;nbsp;of this year.&amp;nbsp;&lt;img id="smileytongue" class="emoticon emoticon-smileytongue" src="https://communities.sas.com/i/smilies/16x16_smiley-tongue.png" alt="Smiley Tongue" title="Smiley Tongue" /&gt;&lt;/P&gt;&lt;P&gt;The&amp;nbsp;code that I provided above works great&amp;nbsp;all the numbers coming as result are correct, the only issue is when the Prod_type changes from one to another, it breaks.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, If I had only one Prod_type, the above code works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 16:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447194#M112279</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T16:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447206#M112282</link>
      <description>&lt;P&gt;Do you need just the final value or all the intermediary values as well?&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 17:24:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447206#M112282</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-20T17:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447207#M112283</link>
      <description>&lt;P&gt;Expected_1 and Expected_2 are my final values. So yes, I want these two.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 17:25:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447207#M112283</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T17:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447215#M112285</link>
      <description>&lt;P&gt;Yes, indeed your program is more complicated than needed.&amp;nbsp; In particular, you should&amp;nbsp;take advantage of two features of the DATA step:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The LAG function, which allows you to access data from preceding records (actually preceding invocation of a lag queue - which in this case is the same thing.&amp;nbsp; For instance you can&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXP1=lag(adjusted_pmpm)*(1+trend)&lt;BR /&gt;and&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; EXP2=lag(exp1)*(1+trend)&lt;BR /&gt;You should probably nest those expressions in a ROUND function to get exact pennies.&lt;BR /&gt;&lt;BR /&gt;&lt;/LI&gt;
&lt;LI&gt;The BY statement (as in &lt;EM&gt;&lt;STRONG&gt;SET HAVE; BY PRODUCT_TYPE;&lt;/STRONG&gt;&lt;/EM&gt;) which allows you to determine whether the record-in-hand is the first record for a product_type (via the automatic variable FIRST.PRODUCT_TYPE).&amp;nbsp;&amp;nbsp;You can use this information to eliminate the unwanted consequences of lagged values carrying over from one product_type to the next:&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a first effort,&amp;nbsp;don't worry about carryover from prior product_types.&amp;nbsp; Just see if you can use the LAG function to generate the 2 new variables EXP1 and EXP2.&amp;nbsp; Once you've got that, then return to the task of setting EXP1 to missing for the first record of each type, and first 2 recs for EXP2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the starting data set, all sasified:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input PROD_TYPE $4.Calendar_year ADJUSTED_PMPM :dollar9.2 Trend percent3.;
datalines;
Advo 2015 $3,304.55 7%
Advo 2016 $3,145.41 7%
Advo 2017 $3,229.17 7%
GRP  2015 $2,956.19 1%
GRP  2016 $3,238.21 1%
GRP  2017 $4,184.82 1%
IFP  2015 $4,706.53 9%
IFP  2016 $4,634.87 9%
IFP  2017 $5,308.22 9%
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 17:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447215#M112285</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-20T17:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447220#M112287</link>
      <description>&lt;P&gt;Wow!! This was great. Never used the lag function before, so didn't&amp;nbsp;know.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code that I tried.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data test_2;
set Non_engaged;
Format EXP1 EXP2 dollar10.2;
by prod_type;
EXP1=lag(adjusted_pmpm)*(1+trend);
EXP2=lag(exp1)*(1+trend);
if first.prod_type then do;
EXP1 = 0;
EXP2 = 0;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Setting EXP1 to missing for the first record&amp;nbsp;for each product type is easy using First.Product_Type. &lt;U&gt;But how do you&amp;nbsp;set first 2 recs for EXP2 to missing??&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 18:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447220#M112287</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T18:31:59Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447225#M112288</link>
      <description>&lt;P&gt;YOu can use lag function on the automatic dummies:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lag(first.product)=1 then exp2=0;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But instead of setting to zero, why not set values to missing?&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp; if first.product then call missing(exp1,exp2);&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;if lag(first.product)=1 then call missing(exp2&lt;/STRONG&gt;&lt;/EM&gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The advantage of the call missing is that it can (1) accept a list of variable, and (2) that list can be a mixture of character and numeric&amp;nbsp; variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can also use the NMISS function on the 3 variables to determine when to calculate the average (by using the MEAN function).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 18:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447225#M112288</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-20T18:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447232#M112291</link>
      <description>&lt;P&gt;Ohh I see. This is how you set the variable to missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I didn't know how to set the variable to missing that's why was setting them to 0.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a ton. I really appreciate all your time.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Mar 2018 18:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447232#M112291</guid>
      <dc:creator>Abhi_Garg</dc:creator>
      <dc:date>2018-03-20T18:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: Trends analysis Calculation Programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447243#M112295</link>
      <description>&lt;P&gt;Before &lt;EM&gt;&lt;STRONG&gt;call missing&lt;/STRONG&gt;&lt;/EM&gt; was added to SAS, you would use an explicit assignment statement:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;To set a numeric variable to missing:&amp;nbsp;&amp;nbsp;&amp;nbsp; X=.;&lt;/LI&gt;
&lt;LI&gt;To set a character variable to missing&amp;nbsp;&amp;nbsp;&amp;nbsp; CVAR='';&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 20 Mar 2018 19:28:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trends-analysis-Calculation-Programming/m-p/447243#M112295</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-03-20T19:28:23Z</dc:date>
    </item>
  </channel>
</rss>

