<?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 Compute Block Conditions with Multiple Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727453#M226253</link>
    <description>&lt;P&gt;I need someone to explain to me what is happening in the background in a compute block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating a report where I am comparing dates from 2 different reports.&amp;nbsp; If there is a mismatching date, then I concatenate them.&amp;nbsp; For example, you can see that the Baseline_Start_Date and Baseline_End_Date did not match between CDM and SM reports, so they are concatenated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="1506"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="240"&gt;
&lt;P&gt;&lt;STRONG&gt;Baseline_Start_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="228"&gt;
&lt;P&gt;&lt;STRONG&gt;Baseline_End_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="162"&gt;
&lt;P&gt;&lt;STRONG&gt;Actual_Start_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="168"&gt;
&lt;P&gt;&lt;STRONG&gt;Actual_End_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="240"&gt;
&lt;P&gt;2023-06-30 (CDM) / 2020-10-20 (SM)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="228"&gt;
&lt;P&gt;2023-06-30 (CDM) / 2020-10-20 (SM)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="162"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="168"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My task is to highlight&amp;nbsp;Baseline_Start_Date when Actual_Start_Date is blank and Baseline_Start_Date is mismatching.&amp;nbsp; I programatically determine if the dates are not matching if the length of the date field is greater than 20.&amp;nbsp; Likewise, I need to highlight&amp;nbsp;Baseline_End_Date when&amp;nbsp;Actual_End_Date and Baseline_End_Date is mismatching.&amp;nbsp; I'm trying to use a compute block, but I'm not sure how this works when using multiple variables in an IF statement.&amp;nbsp; With the code below, it will highlight only when Baseline_Start_Date &amp;gt; 20 regardless of if Actual_Start_Date is blank or not.&amp;nbsp; How do I incorporate the Actual_Start_Date condition as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute Baseline_Start_Date;
     if (missing(Actual_Start_Date)) &amp;amp; length(Baseline_Start_Date) &amp;gt; 20  then do;
          call define('Baseline_Start_Date', "style", "style=[background=yellow]");
     end;
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I specify a compute block, which variable should be placed there?&amp;nbsp; I assumed Baseline_Start_Date because that is the variable that I want to conditionally highlight.&amp;nbsp; But then inside the block, the condition is based on 2 variables (Baseline_Start_Date and Actual_Start_Date).&amp;nbsp; Can someone explain to me how compute blocks work with multiple variables involved?&lt;/P&gt;</description>
    <pubDate>Thu, 18 Mar 2021 15:49:38 GMT</pubDate>
    <dc:creator>djbateman</dc:creator>
    <dc:date>2021-03-18T15:49:38Z</dc:date>
    <item>
      <title>Compute Block Conditions with Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727453#M226253</link>
      <description>&lt;P&gt;I need someone to explain to me what is happening in the background in a compute block.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am creating a report where I am comparing dates from 2 different reports.&amp;nbsp; If there is a mismatching date, then I concatenate them.&amp;nbsp; For example, you can see that the Baseline_Start_Date and Baseline_End_Date did not match between CDM and SM reports, so they are concatenated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="1506"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="240"&gt;
&lt;P&gt;&lt;STRONG&gt;Baseline_Start_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="228"&gt;
&lt;P&gt;&lt;STRONG&gt;Baseline_End_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="162"&gt;
&lt;P&gt;&lt;STRONG&gt;Actual_Start_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="168"&gt;
&lt;P&gt;&lt;STRONG&gt;Actual_End_Date&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="240"&gt;
&lt;P&gt;2023-06-30 (CDM) / 2020-10-20 (SM)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="228"&gt;
&lt;P&gt;2023-06-30 (CDM) / 2020-10-20 (SM)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="162"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="168"&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My task is to highlight&amp;nbsp;Baseline_Start_Date when Actual_Start_Date is blank and Baseline_Start_Date is mismatching.&amp;nbsp; I programatically determine if the dates are not matching if the length of the date field is greater than 20.&amp;nbsp; Likewise, I need to highlight&amp;nbsp;Baseline_End_Date when&amp;nbsp;Actual_End_Date and Baseline_End_Date is mismatching.&amp;nbsp; I'm trying to use a compute block, but I'm not sure how this works when using multiple variables in an IF statement.&amp;nbsp; With the code below, it will highlight only when Baseline_Start_Date &amp;gt; 20 regardless of if Actual_Start_Date is blank or not.&amp;nbsp; How do I incorporate the Actual_Start_Date condition as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;compute Baseline_Start_Date;
     if (missing(Actual_Start_Date)) &amp;amp; length(Baseline_Start_Date) &amp;gt; 20  then do;
          call define('Baseline_Start_Date', "style", "style=[background=yellow]");
     end;
endcomp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I specify a compute block, which variable should be placed there?&amp;nbsp; I assumed Baseline_Start_Date because that is the variable that I want to conditionally highlight.&amp;nbsp; But then inside the block, the condition is based on 2 variables (Baseline_Start_Date and Actual_Start_Date).&amp;nbsp; Can someone explain to me how compute blocks work with multiple variables involved?&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 15:49:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727453#M226253</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2021-03-18T15:49:38Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Block Conditions with Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727461#M226260</link>
      <description>&lt;P&gt;Some example data, just the variables needed for this bit and complete enough Proc Report code would be a good idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 16:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727461#M226260</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-18T16:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Block Conditions with Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727465#M226264</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;&amp;nbsp; My guess is that it has something to do with your COLUMN statement order of variables. The answer to this question will depend on the order in which the variables are defined in the COLUMN statement. This has been explained many times before in the Forum as the "left-to-right" rule of PROC REPORT. If you search you should find it.&lt;BR /&gt;In short, consider this COLUMN statement:&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;column &lt;FONT color="#0000FF"&gt;sex&lt;/FONT&gt; &lt;FONT color="#FF00FF"&gt;age&lt;/FONT&gt; &lt;FONT color="#008000"&gt;height&lt;/FONT&gt; &lt;FONT color="#FF6600"&gt;weight&lt;/FONT&gt;;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;If I want to do something based on age and height, maybe:&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;if &lt;FONT color="#FF00FF"&gt;age = 14&lt;/FONT&gt; and &lt;FONT color="#008000"&gt;height &amp;lt; 60&lt;/FONT&gt; then do;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; call define ( ...... );&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;I cannot make this comparison in a COMPUTE block for &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;AGE&lt;/STRONG&gt;&lt;/FONT&gt;. That's because at the point in time when PROC REPORT is executing the COMPUTE block for &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;AGE&lt;/STRONG&gt;&lt;/FONT&gt;, it has ONLY placed &lt;STRONG&gt;&lt;FONT color="#0000FF"&gt;SEX&lt;/FONT&gt;&lt;/STRONG&gt; and&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt; AGE&lt;/STRONG&gt;&lt;/FONT&gt; on the report row (working from &lt;EM&gt;&lt;STRONG&gt;LEFT to RIGHT&lt;/STRONG&gt;&lt;/EM&gt;). That means in the COMPUTE block for &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;AGE&lt;/STRONG&gt;&lt;/FONT&gt;, PROC REPORT does NOT have any visibility of the value for &lt;FONT color="#008000"&gt;&lt;STRONG&gt;HEIGHT&lt;/STRONG&gt;&lt;/FONT&gt; on that report row. PROC REPORT builds the report row one item at a time, working from left to right and at the point in time when a particular variable is placed on the report row, the COMPUTE block for that variable executes, so, if the comparison needs to be done between 2 items, both items will need to be placed on the report row for a successful comparison.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;On the other hand, in the COMPUTE block for &lt;FONT color="#008000"&gt;&lt;STRONG&gt;HEIGHT&lt;/STRONG&gt;&lt;/FONT&gt;, when the COMPUTE block is being executed, PROC REPORT has placed &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;SEX&lt;/STRONG&gt;&lt;/FONT&gt;, &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;AGE&lt;/STRONG&gt;&lt;/FONT&gt; and &lt;STRONG&gt;&lt;FONT color="#008000"&gt;HEIGHT&lt;/FONT&gt; &lt;/STRONG&gt;on the report row, so both &lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;AGE&lt;/STRONG&gt;&lt;/FONT&gt; and &lt;FONT color="#008000"&gt;&lt;STRONG&gt;HEIGHT&lt;/STRONG&gt; &lt;/FONT&gt;can be tested.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;BR /&gt;Search for some of the other postings on the left-to-right rule of PROC REPORT.&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 16:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727465#M226264</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-03-18T16:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Compute Block Conditions with Multiple Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727470#M226269</link>
      <description>&lt;P&gt;Cynthia,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You saved my day!&amp;nbsp; Thank you!&amp;nbsp; I had a concern like this not long ago, and I completely forgot about the left-to-right thing.&amp;nbsp; This is starting to make sense to me.&amp;nbsp; I am defining Baseline_Start_Date before Actual_Start_Date, so the solution was to simply assign the compute block to Actual_Start_Date instead of Baseline_Start_Date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Mar 2021 16:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compute-Block-Conditions-with-Multiple-Variables/m-p/727470#M226269</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2021-03-18T16:41:38Z</dc:date>
    </item>
  </channel>
</rss>

