<?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: proc report - problem with computed col in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800611#M314998</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388612"&gt;@Konkordanz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that the report items are processed &lt;EM&gt;from left to right&lt;/EM&gt;, but your COMPUTE block for &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; refers to variables that appear on the &lt;EM&gt;right&lt;/EM&gt; side of &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; in the COLUMN statement, so their values are not yet available when &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; is computed. The easiest fix would be to move &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; to the end of the COLUMN statement (or at least to the right of &lt;FONT face="courier new,courier"&gt;sp10&lt;/FONT&gt;). Of course, this would change the column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to avoid this change is to introduce aliases for the variables used in the COMPUTE block. You can then use these "copies" of &lt;FONT face="courier new,courier"&gt;sp4&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;sp7&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;sp10&lt;/FONT&gt;&amp;nbsp;and hide them with NOPRINT:&lt;/P&gt;
&lt;PRE&gt;proc report data=schu2;
column bundesland bev &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;sp4=sp_4 sp7=sp_7 sp10=sp_10&lt;/FONT&gt;&lt;/STRONG&gt; sp3 sp4-sp15;
define bundesland / display;
define bev        / display format=Format.;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;define sp_4       / noprint;
define sp_7       / noprint;
define sp_10      / noprint;&lt;/STRONG&gt;&lt;/FONT&gt;
define sp4-sp13   / display format=Format.;
define sp3        / computed format=Format.;
compute sp3; 
  sp3 = &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;sp_4+sp_7+sp_10&lt;/STRONG&gt;&lt;/FONT&gt;;
endcomp;
run;&lt;/PRE&gt;</description>
    <pubDate>Mon, 07 Mar 2022 10:59:44 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2022-03-07T10:59:44Z</dc:date>
    <item>
      <title>proc report - problem with computed col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800584#M314984</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;within the proc report command I want to create a new column &lt;STRONG&gt;sp3&lt;/STRONG&gt; as a sum of three other columns (&lt;STRONG&gt;sp4, sp7, sp10&lt;/STRONG&gt;). I tried it with following syntax:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=schu2;
column bundesland bev &lt;STRONG&gt;sp3&lt;/STRONG&gt; sp4 sp5 sp6 sp7 sp8 sp9 sp10 sp11 sp12 sp13 sp14 sp15;
define bundesland /display;
define bev /display format=Format.;
define sp4  /display format=Format.;
define sp5  /display format=Format.;
define sp6  /display format=Format.;
define sp7  /display format=Format.;
define sp8  /display format=Format.;
define sp9  /display format=Format.;
define sp10 /display format=Format.;
define sp11 /display format=Format.;
define sp12 /display format=Format.;
define sp13 /display format=Format.;
&lt;STRONG&gt;define sp3 / computed format=Format.;
compute sp3; 
	sp3 =sp4+sp7+sp10;
endcomp;&lt;/STRONG&gt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Problem: That doesnt work. Alternativ I tried _c4_+_c7_+_c10_. That doesnt work neither. Afterwards I wanted to know, if the syntax in general is correct...so I tried sp3=1+2. That works. So...Do you know where the error lies?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thank you!&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 09:10:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800584#M314984</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2022-03-07T09:10:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - problem with computed col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800611#M314998</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/388612"&gt;@Konkordanz&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem is that the report items are processed &lt;EM&gt;from left to right&lt;/EM&gt;, but your COMPUTE block for &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; refers to variables that appear on the &lt;EM&gt;right&lt;/EM&gt; side of &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; in the COLUMN statement, so their values are not yet available when &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; is computed. The easiest fix would be to move &lt;FONT face="courier new,courier"&gt;sp3&lt;/FONT&gt; to the end of the COLUMN statement (or at least to the right of &lt;FONT face="courier new,courier"&gt;sp10&lt;/FONT&gt;). Of course, this would change the column order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to avoid this change is to introduce aliases for the variables used in the COMPUTE block. You can then use these "copies" of &lt;FONT face="courier new,courier"&gt;sp4&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;sp7&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;sp10&lt;/FONT&gt;&amp;nbsp;and hide them with NOPRINT:&lt;/P&gt;
&lt;PRE&gt;proc report data=schu2;
column bundesland bev &lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;sp4=sp_4 sp7=sp_7 sp10=sp_10&lt;/FONT&gt;&lt;/STRONG&gt; sp3 sp4-sp15;
define bundesland / display;
define bev        / display format=Format.;
&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;define sp_4       / noprint;
define sp_7       / noprint;
define sp_10      / noprint;&lt;/STRONG&gt;&lt;/FONT&gt;
define sp4-sp13   / display format=Format.;
define sp3        / computed format=Format.;
compute sp3; 
  sp3 = &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;sp_4+sp_7+sp_10&lt;/STRONG&gt;&lt;/FONT&gt;;
endcomp;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 07 Mar 2022 10:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800611#M314998</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-03-07T10:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - problem with computed col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800613#M314999</link>
      <description>&lt;P&gt;The way PROC REPORT works is left to right. So when sp3 comes to the left of sp4 and left of sp7 and left of sp10, the math can't be done because as sp3 is being computed, it does not know about the values of sp4 and sp7 and sp10.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 11:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800613#M314999</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-07T11:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - problem with computed col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800615#M315000</link>
      <description>&lt;P&gt;Okay, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 11:02:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800615#M315000</guid>
      <dc:creator>Konkordanz</dc:creator>
      <dc:date>2022-03-07T11:02:24Z</dc:date>
    </item>
    <item>
      <title>Re: proc report - problem with computed col</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800619#M315002</link>
      <description>&lt;P&gt;Since sp3 comes before the other variables in the COLUMN statement, and variables are resolved by the order defined in that statement, you get missing values.&lt;/P&gt;
&lt;P&gt;Define "hidden" aliases which you can use in the COMPUTE:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=schu2;
column bundesland bev sp4=s4 sp7=s7 sp10=s10 sp3 sp4 sp5 sp6 sp7 sp8 sp9 sp10 sp11 sp12 sp13 sp14 sp15;
define bundesland /display;
define s4 / noprint;
define s7 / noprint;
define s10 / noprint;
define bev /display format=Format.;
define sp4  /display format=Format.;
define sp5  /display format=Format.;
define sp6  /display format=Format.;
define sp7  /display format=Format.;
define sp8  /display format=Format.;
define sp9  /display format=Format.;
define sp10 /display format=Format.;
define sp11 /display format=Format.;
define sp12 /display format=Format.;
define sp13 /display format=Format.;
define sp3 / computed format=Format.;
compute sp3; 
  sp3 = sum(s4,s7,s10);
endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The SUM() function takes care of missing values in the variables (counting them &amp;nbsp;as 0). You will now get a missing value only when &lt;EM&gt;all three&lt;/EM&gt; source variables are missing.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 11:10:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-report-problem-with-computed-col/m-p/800619#M315002</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-07T11:10:20Z</dc:date>
    </item>
  </channel>
</rss>

