<?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 calculate a new variable using variables * cases in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47381#M449</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I thought it was something like this! I tried using &amp;amp; but it gave me error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. It did give me what I want. Do you have any idea how to output the result in a new table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it something like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table work.newtable as select * from ........?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Aug 2011 20:10:56 GMT</pubDate>
    <dc:creator>JOLSAS</dc:creator>
    <dc:date>2011-08-12T20:10:56Z</dc:date>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47372#M440</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a data set looking like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 192px; border-collapse: collapse;"&gt;&lt;TBODY&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD height="20" style="width: 48pt; height: 15pt;" width="64"&gt;year&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;shr&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;opt&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1992&lt;/TD&gt;&lt;TD align="right"&gt;2.4&lt;/TD&gt;&lt;TD align="right"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1992&lt;/TD&gt;&lt;TD align="right"&gt;2.3&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1992&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD align="right"&gt;86&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD align="right"&gt;6.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD align="right"&gt;2.3&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD align="right"&gt;2.6&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD align="right"&gt;3.5&lt;/TD&gt;&lt;TD align="right"&gt;8.9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to output a new table looking like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 96pt; border-collapse: collapse;" width="128"&gt;&lt;TBODY&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD height="20" style="width: 48pt; height: 15pt;" width="64"&gt;year&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;new variable&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1992&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;1993&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;where the new variable is the average of shr * opt in all the years.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;e.g.&amp;nbsp;&amp;nbsp;&amp;nbsp; the new variable for 1992 equals (2.4 * 6 + 2.3 * . + . * 86)/3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; and the new variable for 1993 equals ( . * 6.5 + . * . + 2.3 * 0 + 2.6 * 0 + 3.5 * 8.9)/5&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to output the new variable for each year.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any idea how to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 01:37:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47372#M440</guid>
      <dc:creator>JOLSAS</dc:creator>
      <dc:date>2011-08-12T01:37:55Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47373#M441</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There are definitely fancier ways of doing this but, hopefully, this will be more useful in showing you how such results are calculated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input year&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;shr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;opt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;1992&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/P&gt;&lt;P&gt;1992&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;1992&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;86&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6.5&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2.6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;0&lt;/P&gt;&lt;P&gt;1993&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8.9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data temp (keep=year data);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if shr &amp;gt; 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=shr;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if opt &amp;gt; 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data=opt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data=temp nway mean;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var data;&lt;/P&gt;&lt;P&gt;&amp;nbsp; class year;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output out=want (drop=_:)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean=average n=count;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 05:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47373#M441</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-12T05:03:47Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47374#M442</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I believe this code is pretty straightforward:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; work.detail_data;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Year&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; shr&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; opt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;datalines&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1992 2.4 6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1992 2.3 .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1992 . 86&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1993 . 6.5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1993 2.3 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1993 2.6 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffc0; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;1993 3.5 8.9&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; avg(shr*opt) &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; NewVar&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; work.detail_data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It produces this output:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE cellpadding="7" cellspacing="1" class="Table" frame="box" rules="groups" summary="Procedure SQL: Query Results"&gt;&lt;THEAD&gt;&lt;TR&gt;&lt;TH class="r b Header" scope="col"&gt;Year&lt;/TH&gt;&lt;TH class="r b Header" scope="col"&gt;NewVar&lt;/TH&gt;&lt;/TR&gt;&lt;/THEAD&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="r Data"&gt;1992&lt;/TD&gt;&lt;TD class="r Data"&gt;14.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD class="r Data"&gt;1993&lt;/TD&gt;&lt;TD class="r Data"&gt;10.38333&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 13:13:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47374#M442</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-08-12T13:13:25Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47375#M443</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I obviously didn't notice the asterisks in the definition.&amp;nbsp; However, you should be able to modify that yourself and now have two methods and can choose depending upon your preferences.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But, now that I know you want to multiply the two values, what effect to you want missing values to have?&amp;nbsp; What if both values are missing?&amp;nbsp; I.e., should missing&amp;nbsp; and/or zero values be included, should they cancel out the results for the entire equation, and/or should they be used or dismissed in the numerator? .. in the denominator?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 13:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47375#M443</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-12T13:21:58Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47376#M444</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I think you're right.&amp;nbsp; The standard average function doesn't calculate the same way the OP's formula does.&amp;nbsp; To accomplish that, I think he would have to change my formula from avg(shr*opt) to sum(shr*opt)/count(*).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 13:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47376#M444</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-08-12T13:34:25Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47377#M445</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In the example, ( . * 6.5 + . * . + 2.3 * 0 + 2.6 * 0 + 3.5 * 8.9)/5 would equal to (. + . + 0 + 0 + 3.5 * 8.9)/5 = 3.5 * 8.9 / 5 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does this make sense? Basically, if either of the two existing variables is missing, this makes the product of that line a missing value. But I think this wouldn't affect the entire equation. In the case of zeores, the product would be zero. But since I don't know for sure if the equation for each year contains how many missing values/zeroes/"good" values, I have to count all of them.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 19:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47377#M445</guid>
      <dc:creator>JOLSAS</dc:creator>
      <dc:date>2011-08-12T19:18:30Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47378#M446</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I think the normal SAS average function excludes null values from the denominator as well.&amp;nbsp; So, your calculation would end up being divided by 3 instead of 5.&amp;nbsp; If that's what you want, then you could use it.&amp;nbsp; If not, then you'll have to calculate it as sum(shr*opt)/count(*) which would equate to 3.5*8.9.5&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 19:43:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47378#M446</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-08-12T19:43:30Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47379#M447</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks. Including null values is what I want. I ran your code, and it gave me very good results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now the thing is, a few different companies have these year-data. It;s like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 192pt; border-collapse: collapse;" width="256"&gt;&lt;TBODY&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD height="20" style="width: 48pt; height: 15pt;" width="64"&gt;gvkey&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;year&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;shr&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;opt&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;2.4&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;6&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;2.3&lt;/TD&gt;&lt;TD class="xl63" style="width: 48pt;" width="64"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD class="xl63" style="width: 48pt;" width="64"&gt;.&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;86&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD class="xl63" style="width: 48pt;" width="64"&gt;.&lt;/TD&gt;&lt;TD class="xl63" style="width: 48pt;" width="64"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;2.3&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;3.5&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;8.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;3.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;3.5&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;6&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;8.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1994&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;1994&lt;/TD&gt;&lt;TD align="right"&gt;0&lt;/TD&gt;&lt;TD class="xl64" style="width: 48pt;" width="64"&gt;2.3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If only group by year, the sas would return me average values for all the company in each year. What if I want average value of each company in each year?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the case above, the output would be like:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 144pt; border-collapse: collapse;" width="192"&gt;&lt;TBODY&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD height="20" style="width: 48pt; height: 15pt;" width="64"&gt;gvkey&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;year&lt;/TD&gt;&lt;TD style="width: 48pt;" width="64"&gt;newvar&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl65" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;105&lt;/TD&gt;&lt;TD class="xl65" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl65" style="width: 48pt;" width="64"&gt;1992&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl65" style="width: 48pt;" width="64"&gt;1993&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR style="height: 15pt;"&gt;&lt;TD align="right" height="20" style="height: 15pt;"&gt;258&lt;/TD&gt;&lt;TD class="xl65" style="width: 48pt;" width="64"&gt;1994&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas? Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;BTW, sometimes sql does lots of things with relatively simple codes! A good idea to use sql in this case!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 19:57:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47379#M447</guid>
      <dc:creator>JOLSAS</dc:creator>
      <dc:date>2011-08-12T19:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47380#M448</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;By the way...including null values like you're doing effectively sets the value for that row to zero and includes it.&amp;nbsp; That's why the normal average function excludes null values as they aren't technically the same as zero.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;select&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gvkey,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; year,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum(shr*opt)/count(*) &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; NewVar&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; work.detail_data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;group&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; gvkey, year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="background-color: white; font-family: 'Courier New'; color: navy; font-size: 10pt;"&gt;quit&lt;/STRONG&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 20:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47380#M448</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-08-12T20:02:59Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47381#M449</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; I thought it was something like this! I tried using &amp;amp; but it gave me error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you. It did give me what I want. Do you have any idea how to output the result in a new table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it something like &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table work.newtable as select * from ........?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 20:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47381#M449</guid>
      <dc:creator>JOLSAS</dc:creator>
      <dc:date>2011-08-12T20:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47382#M450</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;JolSAS,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, sometimes SQL can do things that are difficult in a datastep.&amp;nbsp; Of course, sometimes one can do things in a datastep that are difficult if not impossible to do with SQL.&amp;nbsp; However, my bigger concern if I were you, is what are the two values you are multiplying.&amp;nbsp; With your chosen computational technique you may be throwing some babies out with the bath water.&amp;nbsp; Similarly, one of the values may be meant as a weight.&amp;nbsp; The forum doesn't know what the data represent.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 20:12:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47382#M450</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-12T20:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47383#M451</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you only need to insert the line&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;create table work.newtable as &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;before your select statement&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you don't want the output shown on your screen, change the proc sql; line to&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 20:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47383#M451</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-08-12T20:14:40Z</dc:date>
    </item>
    <item>
      <title>calculate a new variable using variables * cases</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47384#M452</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; The shr is shares of options owned and the opt is value realized from option exercising.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, shr is a weight and I'm trying to compute the weighted average over the years. The reason that one company, in one year, could have multiple lines, is because one company, in one year, have multiple executives. One executive could have no share of options, while another could have some. Therefore, there are numbers and missing values. As a matter of fact, I cannot be 100% sure on this either. I think the best I can do is to try both sum/count and the average function, and see which produces the better result. In fact, I just asked my professor for his opinion.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Aug 2011 20:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/calculate-a-new-variable-using-variables-cases/m-p/47384#M452</guid>
      <dc:creator>JOLSAS</dc:creator>
      <dc:date>2011-08-12T20:34:06Z</dc:date>
    </item>
  </channel>
</rss>

