<?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: make a new variable based on two observations in a table in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720943#M27751</link>
    <description>&lt;P&gt;A few questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1. In your example, why isn't pos_perc calculated for the first row? Is there a rule for which rows to calculate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2. Can you elaborate on how this data is updated? I presume it is a SAS dataset that is updated daily, and that you want to pos_perc calculation to&amp;nbsp; be refreshed afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3. Is Positive in row 2 supposed to be 433 or 450? Your example shows both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're looking for something that will automatically "refresh" the calculation, you could try a SAS view:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input Total Persons Positive &amp;amp; date_or_text $32.;
    datalines;
1678899  4568788  294665  22feb2021
106113  5623  450  Changes since the day before
;
run;

proc sql;
    create view want as
    select *
          ,(positive / total) * 100 as pos_perc format 8.2
    from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2021 15:58:22 GMT</pubDate>
    <dc:creator>mklangley</dc:creator>
    <dc:date>2021-02-22T15:58:22Z</dc:date>
    <item>
      <title>make a new variable based on two observations in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720916#M27745</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I have this kind of table based on a proc compare data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="25%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;Total&lt;/TD&gt;
&lt;TD width="10%"&gt;Persons&lt;/TD&gt;
&lt;TD width="10%"&gt;Positive&lt;/TD&gt;
&lt;TD width="10%"&gt;date_or_text&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1678899&lt;/TD&gt;
&lt;TD width="10%"&gt;4568788&lt;/TD&gt;
&lt;TD width="10%"&gt;294665&lt;/TD&gt;
&lt;TD width="10%"&gt;22feb2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;2&lt;/TD&gt;
&lt;TD width="10%"&gt;106113&lt;/TD&gt;
&lt;TD width="10%"&gt;5623&lt;/TD&gt;
&lt;TD width="10%"&gt;433&lt;/TD&gt;
&lt;TD width="10%"&gt;Changes since the day before&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to add a new variable to this table with the positive percentages. it should take the "Positve" number from line 2 divided by the "total" number from line 2 times 100. it should be in mind that these numbers changes everyday. So I cant type the numbers manually in.&lt;/P&gt;
&lt;P&gt;the wished ouput:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1" width="79.55182072829132%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="10%"&gt;Total&lt;/TD&gt;
&lt;TD width="10%"&gt;Persons&lt;/TD&gt;
&lt;TD width="10%"&gt;Positive&lt;/TD&gt;
&lt;TD width="5%"&gt;date_or_text&lt;/TD&gt;
&lt;TD width="5%"&gt;Pos_perc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;1&lt;/TD&gt;
&lt;TD width="10%"&gt;1678899&lt;/TD&gt;
&lt;TD width="10%"&gt;4568788&lt;/TD&gt;
&lt;TD width="10%"&gt;294665&lt;/TD&gt;
&lt;TD width="5%"&gt;22feb2021&lt;/TD&gt;
&lt;TD width="5%"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="10%"&gt;2&lt;/TD&gt;
&lt;TD width="10%"&gt;106113&lt;/TD&gt;
&lt;TD width="10%"&gt;5623&lt;/TD&gt;
&lt;TD width="10%"&gt;450&lt;/TD&gt;
&lt;TD width="5%"&gt;Changes since the day before&lt;/TD&gt;
&lt;TD width="5%"&gt;0,42&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Mon, 22 Feb 2021 14:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720916#M27745</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-02-22T14:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: make a new variable based on two observations in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720938#M27749</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353472"&gt;@mmea&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you just want the percentage calculation done for observation number 2, then you could try something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;

   if _n_ = 2 then
      pos_perc = (positive / total) * 100;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want the calculation done for all observations then you can remove the line "if _n_ = 2 then".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want something different then please provide more information and explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 15:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720938#M27749</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-02-22T15:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: make a new variable based on two observations in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720943#M27751</link>
      <description>&lt;P&gt;A few questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 1. In your example, why isn't pos_perc calculated for the first row? Is there a rule for which rows to calculate?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 2. Can you elaborate on how this data is updated? I presume it is a SAS dataset that is updated daily, and that you want to pos_perc calculation to&amp;nbsp; be refreshed afterwards.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; 3. Is Positive in row 2 supposed to be 433 or 450? Your example shows both.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you're looking for something that will automatically "refresh" the calculation, you could try a SAS view:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input Total Persons Positive &amp;amp; date_or_text $32.;
    datalines;
1678899  4568788  294665  22feb2021
106113  5623  450  Changes since the day before
;
run;

proc sql;
    create view want as
    select *
          ,(positive / total) * 100 as pos_perc format 8.2
    from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 15:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/720943#M27751</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2021-02-22T15:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: make a new variable based on two observations in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/721211#M27770</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;My mistake - the number should be the same for positives in both examples.&lt;/P&gt;
&lt;P&gt;My data is updated everyday, so I need a refreshed number everyday.&lt;/P&gt;
&lt;P&gt;Only for the second row - as the first row tells me the numbers for covid in the whole period - and the second row are today.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 08:51:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/721211#M27770</guid>
      <dc:creator>mmea</dc:creator>
      <dc:date>2021-02-23T08:51:20Z</dc:date>
    </item>
    <item>
      <title>Re: make a new variable based on two observations in a table</title>
      <link>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/721214#M27771</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/353472"&gt;@mmea&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the update. As no post has been marked as a solution, does this mean you still need a solution? In which case, please share what code you have tried, what result you received, and what result you actually wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks &amp;amp; kind regards,&lt;/P&gt;
&lt;P&gt;Amir.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Feb 2021 09:01:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/make-a-new-variable-based-on-two-observations-in-a-table/m-p/721214#M27771</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2021-02-23T09:01:58Z</dc:date>
    </item>
  </channel>
</rss>

