<?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 create this variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786180#M250979</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc sort data=have;
    by descending quarter;
run;
data want;
    set have;
    retain pse_calc 1;
    pse_calc=pse_calc*(1+pse);
run;
proc sort data=want;
    by quarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want tested code, please provide the data as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
    <pubDate>Wed, 15 Dec 2021 14:30:43 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-12-15T14:30:43Z</dc:date>
    <item>
      <title>How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786170#M250975</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this table:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;quarter&lt;/TD&gt;&lt;TD&gt;pse&lt;/TD&gt;&lt;TD&gt;psn&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q1&lt;/TD&gt;&lt;TD&gt;0.976&lt;/TD&gt;&lt;TD&gt;0.77&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q2&lt;/TD&gt;&lt;TD&gt;0.987&lt;/TD&gt;&lt;TD&gt;0.76&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q3&lt;/TD&gt;&lt;TD&gt;0.56&lt;/TD&gt;&lt;TD&gt;0.954&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q4&lt;/TD&gt;&lt;TD&gt;0.77&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;0.876&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;i need to create roll up measure form each variable (pse,psn) like the example below:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;quarter&lt;/TD&gt;&lt;TD&gt;pse&lt;/TD&gt;&lt;TD&gt;psn&lt;/TD&gt;&lt;TD&gt;pse_clac&lt;/TD&gt;&lt;TD&gt;psn_clac&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q1&lt;/TD&gt;&lt;TD&gt;0.976&lt;/TD&gt;&lt;TD&gt;0.77&lt;/TD&gt;&lt;TD&gt;10.84133&lt;/TD&gt;&lt;TD&gt;11.4194&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q2&lt;/TD&gt;&lt;TD&gt;0.987&lt;/TD&gt;&lt;TD&gt;0.76&lt;/TD&gt;&lt;TD&gt;5.486504&lt;/TD&gt;&lt;TD&gt;6.451639&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q3&lt;/TD&gt;&lt;TD&gt;0.56&lt;/TD&gt;&lt;TD&gt;0.954&lt;/TD&gt;&lt;TD&gt;2.7612&lt;/TD&gt;&lt;TD&gt;3.665704&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;q4&lt;/TD&gt;&lt;TD&gt;0.77&lt;/TD&gt;&lt;TD&gt;0.876&lt;/TD&gt;&lt;TD&gt;1.77&lt;/TD&gt;&lt;TD&gt;1.876&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pse_calc for q1=&amp;nbsp;(1+0.876)*(1+9.54)*(1+0.76)*(1+0.77)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q2=&amp;nbsp;(1+0.876)*(1+9.54)*(1+0.76)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; q3=(1+0.876)*(1+9.54)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q4=(1+0.876)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 13:58:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786170#M250975</guid>
      <dc:creator>jony123</dc:creator>
      <dc:date>2021-12-15T13:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786180#M250979</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc sort data=have;
    by descending quarter;
run;
data want;
    set have;
    retain pse_calc 1;
    pse_calc=pse_calc*(1+pse);
run;
proc sort data=want;
    by quarter;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want tested code, please provide the data as SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 14:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786180#M250979</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-15T14:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786198#M250983</link>
      <description>&lt;P&gt;You really should state your rules. This appears to use values of other rows &lt;STRONG&gt;however&lt;/STRONG&gt; you show (1+9.54) when the apparent variable value you show is .954. So why would only the .954 by multiplied by 10 when none of the other values are?&lt;/P&gt;
&lt;P&gt;And since you show nothing using the PSE variable does it have a similar exception?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 15:53:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786198#M250983</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-15T15:53:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786201#M250984</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You really should state your rules. This appears to use values of other rows &lt;STRONG&gt;however&lt;/STRONG&gt; you show (1+9.54) when the apparent variable value you show is .954. So why would only the .954 by multiplied by 10 when none of the other values are?&lt;/P&gt;
&lt;P&gt;And since you show nothing using the PSE variable does it have a similar exception?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;These are good points. Also, in this code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;pse_calc for q1= (1+0.876)*(1+9.54)*(1+0.76)*(1+0.77)
                   q2= (1+0.876)*(1+9.54)*(1+0.76)
                  q3=(1+0.876)*(1+9.54)
                 q4=(1+0.876)&lt;/PRE&gt;
&lt;P&gt;the value being calculated is called &lt;FONT color="#FF0000"&gt;pse&lt;/FONT&gt;_calc but the numbers used are from the &lt;FONT color="#FF0000"&gt;psn&lt;/FONT&gt; variable.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/235130"&gt;@jony123&lt;/a&gt;&amp;nbsp;you need to clear up these issues.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Dec 2021 16:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786201#M250984</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-15T16:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786204#M250985</link>
      <description>&lt;P&gt;Given those furmula you need to do the calculations in reverse chronological order. So sort the data with DESCENDING option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input quarter $ pse psn pse_clac psn_clac ;
cards;
q1 0.976 0.77 10.84133 11.4194
q2 0.987 0.76 5.486504 6.451639
q3 0.56 0.954 2.7612 3.665704
q4 0.77 0.876 1.77 1.876
;

proc sort;
  by descending quarter;
run;

data want;
  set have;
  by descending quarter;
  retain pse_new 1 psn_new 1;
  pse_new=pse_new*(1+pse);
  psn_new=psn_new*(1+psn);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    quarter     pse      psn     pse_clac    psn_clac    pse_new    psn_new

 1       q4       0.770    0.876      1.7700      1.8760     1.7700     1.8760
 2       q3       0.560    0.954      2.7612      3.6657     2.7612     3.6657
 3       q2       0.987    0.760      5.4865      6.4516     5.4865     6.4516
 4       q1       0.976    0.770     10.8413     11.4194    10.8413    11.4194

&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Dec 2021 16:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786204#M250985</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-12-15T16:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to create this variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786285#M251020</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input quarter $ pse psn ;
id+1;
cards;
q1 0.976 0.77 
q2 0.987 0.76 
q3 0.56 0.954 
q4 0.77 0.876 
;

proc sql;
create table want as
select distinct a.*,
 10**sum(log10(1+b.pse)) as pse_clac ,
 10**sum(log10(1+b.psn)) as psn_clac
 from have as a,have as b
  where a.id&amp;lt;=b.id
   group by a.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Dec 2021 12:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-this-variable/m-p/786285#M251020</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-12-16T12:17:26Z</dc:date>
    </item>
  </channel>
</rss>

