<?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 How to Use an Order Variable in a Compute Block in Proc Report in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332581#M62780</link>
    <description>&lt;P&gt;HI there,&lt;/P&gt;
&lt;P&gt;I would like to do an action on a particular cell in Proc Report conditional on the value of other variables on that record. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the generic data below for example I would like weight to show red whenever married=1 or ed=2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "married condition" is partially working in that weight is highlighted red for the first record with married=1. &amp;nbsp;However it doesnt work for the rest of the records and this seems to be down to the fact that married is an order variable and not repeating. &amp;nbsp;I do require married to be an ordered variable so I wonder how I can make the compute block look at the actual value here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly the "ed" condition isn't working at all and I can see no reason why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is probably down to being relatively new to Proc Report but any help much appreciated!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data base;
set sashelp.bweight  (obs=25);
run;

proc report data = base;
col  married boy smoke weight ed;
define married / order;
define boy / order;
define smoke / order; 
define weight / display;
define ed / display;
compute weight;
  if married=1 then  do;
      call define(_col_,"style","style={background=red}");
  end;
  else if ed=2 then do;
  	      call define(_col_,"style","style={background=red}");
  end;
endcomp;

compute after married;
    line ' ';	
endcomp;
compute after boy;
    line ' ';	
endcomp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 14 Feb 2017 12:49:54 GMT</pubDate>
    <dc:creator>IrishGuy</dc:creator>
    <dc:date>2017-02-14T12:49:54Z</dc:date>
    <item>
      <title>How to Use an Order Variable in a Compute Block in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332581#M62780</link>
      <description>&lt;P&gt;HI there,&lt;/P&gt;
&lt;P&gt;I would like to do an action on a particular cell in Proc Report conditional on the value of other variables on that record. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the generic data below for example I would like weight to show red whenever married=1 or ed=2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The "married condition" is partially working in that weight is highlighted red for the first record with married=1. &amp;nbsp;However it doesnt work for the rest of the records and this seems to be down to the fact that married is an order variable and not repeating. &amp;nbsp;I do require married to be an ordered variable so I wonder how I can make the compute block look at the actual value here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly the "ed" condition isn't working at all and I can see no reason why.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is probably down to being relatively new to Proc Report but any help much appreciated!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data base;
set sashelp.bweight  (obs=25);
run;

proc report data = base;
col  married boy smoke weight ed;
define married / order;
define boy / order;
define smoke / order; 
define weight / display;
define ed / display;
compute weight;
  if married=1 then  do;
      call define(_col_,"style","style={background=red}");
  end;
  else if ed=2 then do;
  	      call define(_col_,"style","style={background=red}");
  end;
endcomp;

compute after married;
    line ' ';	
endcomp;
compute after boy;
    line ' ';	
endcomp;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Feb 2017 12:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332581#M62780</guid>
      <dc:creator>IrishGuy</dc:creator>
      <dc:date>2017-02-14T12:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use an Order Variable in a Compute Block in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332591#M62781</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the value of an order variable is only available in the very first row, you need to put the value aside.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The followingcode sample illustrates the basic principle on how to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=sashelp.class;
  column age name sex _dummy;
  define age / order;
  define name / display;
  define sex / display;
  define _dummy / computed;

  compute _dummy / char length=32;
    if missing(age) = 0 then do;
      saveAge = age;
    end;
    _dummy = cats("age=", age, ",saveAge=", saveAge);
  endcomp;
  compute after age;
    line " ";
  endcomp;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would recommend to add a "dummy" column add the very end to your report. In the compute block of this dummy variable, you have access to all the variables to left in your report.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The dummy varibale does not need to be printed, so simply add the NOPRINT option in the define statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 13:08:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332591#M62781</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-02-14T13:08:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use an Order Variable in a Compute Block in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332609#M62782</link>
      <description>&lt;P&gt;That works really welly. &amp;nbsp;I also hadn't realized that the vars used in the compute block need to be to the left of the computed var. &amp;nbsp;Cheers!&lt;/P&gt;</description>
      <pubDate>Tue, 14 Feb 2017 13:55:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-Use-an-Order-Variable-in-a-Compute-Block-in-Proc-Report/m-p/332609#M62782</guid>
      <dc:creator>IrishGuy</dc:creator>
      <dc:date>2017-02-14T13:55:54Z</dc:date>
    </item>
  </channel>
</rss>

