Rhodochrosite | Level 12

## Comparing Column Using Compute

Comparing Column Using Compute

For some reason the value of growthDeclineColumn is not recognizing as 1.

In a compute block.  I’m using the logic.

if growthDeclineColumn eq 1 then call define(_col_,'style','style={font_weight=bold}');

In the datastep I set

growthDeclineColumn = 1;

Am I missing something here that is not allowing the value to be defined as 1?

I included a screenshot of the report without the compute block working.

1 ACCEPTED SOLUTION

Accepted Solutions
Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

The bug is that compute only lets you compare on the column following the word compute.

11 REPLIES 11
Diamond | Level 26

## Re: Comparing Column Using Compute

Are you sure it is actually 1, not just SAS hiding a tiny fraction behind the scenes, e.g. 1.0000000000000001.   This sometimes happens on calculations.  Try:

if 0.99 < growthDeclineColumn < 1.001 then...;

or

if int(growthDeclineColumn) = 1 then...;

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

Tried both with no luck.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

Below is the full code.

data all;

/*length GENDER_DESC \$ 34;

input GENDER_DESC \$34. ACADEMIC_PERIOD_DESC \$10. n growthDeclineColumn perGrowthDeclineColumn;

datalines;

data all;

infile datalines dsd;

input GENDER_DESC : \$34. ACADEMIC_PERIOD_DESC : \$10. n growthDeclineColumn perGrowthDeclineColumn;

datalines;

Female,Fall 2010,18525.00,0,0

Female,Fall 2011,18345.00,0,0

Female,Fall 2012,18097.00,0,0

Female,Fall 2013,17792.00,0,0

Female,Fall 2014,17755.00,0,0

Male,Fall 2010,13312.00,0,0

Male,Fall 2011,13288.00,0,0

Male,Fall 2012,13391.00,0,0

Male,Fall 2013,13133.00,0,0

Male,Fall 2014,13019.00,0,0

N/R,Fall 2010,466.00,0,0

N/R,Fall 2011,266.00,0,0

N/R,Fall 2012,264.00,0,0

N/R,Fall 2013,363.00,0,0

N/R,Fall 2014,389.00,0,0

Total,Fall 2010,32303.00,0,0

Total,Fall 2011,31899.00,0,0

Total,Fall 2012,31752.00,0,0

Total,Fall 2013,31288.00,0,0

Total,Fall 2014,31163.00,0,0

% Growth/(Decline) over prior Fall,Fall 2010,.,0,1

% Growth/(Decline) over prior Fall,Fall 2011,-0.01,0,1

% Growth/(Decline) over prior Fall,Fall 2012,-0.00,0,1

% Growth/(Decline) over prior Fall,Fall 2013,-0.01,0,1

% Growth/(Decline) over prior Fall,Fall 2014,-0.00,0,1

;

proc print data=all;

run;

/************start report output***********/

proc report data=all missing;

column (gender_desc growthDeclineColumn perGrowthDeclineColumn academic_period_desc, n);

define gender_desc / group  '' order=data;

define growthDeclineColumn / group '' order = data;

define perGrowthDeclineColumn / group '' order = data;

define academic_period_desc / across '' order=data;

define n / analysis sum '' FORMAT=comma8.;

compute gender_desc;

if growthDeclineColumn eq 1 then call define(_col_,'style','style={font_weight=bold}');

if perGrowthDeclineColumn eq 1 then call define(_col_,'style','style={font_weight=bold}');

endcomp;

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

compute gender_desc;

/*if growthDeclineColumn = 1 then do; (does not work)*/

if gender_desc = 'Female' then do;  /*(works)*/

call define(_col_,'style','style={font_weight=bold}');

end;

if perGrowthDeclineColumn eq 1 then call define(_col_,'style','style={font_weight=bold}');

endcomp;

Not sure what is special about my number.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

Maybe my number is being treated as a character in a wacky format.  I did a ne = ‘a’ and got a result.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

compute gender_desc;

if growthDeclineColumn = . then

call define(_col_,'style','style={font_weight=bold}');

if perGrowthDeclineColumn eq 1 then call define(_col_,'style','style={font_weight=bold}');

endcomp;

The value of growthDeclineColumn is null this bolds.   This is  crazy, is there a work around for this bug?  Note I'm using 9.2.  The bug occurs in enterprise guide.

Diamond | Level 26

## Re: Comparing Column Using Compute

Its not something like:

if growthDeclineColumn = 1.00

Can't tell from the data as not at work now, can have a look tomorrow see if it does the same thing in SAS 9.3.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

The bug is that compute only lets you compare on the column following the word compute.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

What I want to do is format the value of only one other column based on the value of another.

Rhodochrosite | Level 12

## Re: Comparing Column Using Compute

Here is the bug explanation:

Somewhere in the middle of the doc:

Base SAS(R) 9.2 Procedures Guide

If a compute block is associated with a report item, then PROC REPORT executes the compute block on every row of the report when it comes to the column for that item. The value of a computed variable in any row of a report is the last value assigned to that variable during that execution of the DATA step statements in the compute block. PROC REPORT assigns values to the columns in a row of a report from left to right. Consequently, you cannot base the calculation of a computed variable on any variable that appears to its right in the report.

## Re: Comparing Column Using Compute

I think this is right (what you want).  Since the variables used in the COMPUTE block comparison are GROUP you need to HOLD there values in temporary variables that do "become missing".

data all;
infile datalines dsd;

input GENDER_DESC : \$34. ACADEMIC_PERIOD_DESC : \$10. n growthDeclineColumn perGrowthDeclineColumn;
datalines;
Female,Fall 2010,18525.00,0,0
Female,Fall 2011,18345.00,0,0
Female,Fall 2012,18097.00,0,0
Female,Fall 2013,17792.00,0,0
Female,Fall 2014,17755.00,0,0
Male,Fall 2010,13312.00,0,0
Male,Fall 2011,13288.00,0,0
Male,Fall 2012,13391.00,0,0
Male,Fall 2013,13133.00,0,0
Male,Fall 2014,13019.00,0,0
N/R,Fall 2010,466.00,0,0
N/R,Fall 2011,266.00,0,0
N/R,Fall 2012,264.00,0,0
N/R,Fall 2013,363.00,0,0
N/R,Fall 2014,389.00,0,0
Total,Fall 2010,32303.00,0,0
Total,Fall 2011,31899.00,0,0
Total,Fall 2012,31752.00,0,0
Total,Fall 2013,31288.00,0,0
Total,Fall 2014,31163.00,0,0
% Growth/(Decline) over prior Fall,Fall 2010,.,0,1
% Growth/(Decline) over prior Fall,Fall 2011,-0.01,0,1
% Growth/(Decline) over prior Fall,Fall 2012,-0.00,0,1
% Growth/(Decline) over prior Fall,Fall 2013,-0.01,0,1
% Growth/(Decline) over prior Fall,Fall 2014,-0.00,0,1
;

proc print data=all;
run;

/************start report output***********/
proc report data=all missing;
column (gender_desc growthDeclineColumn perGrowthDeclineColumn academic_period_desc, n);
define gender_desc / group  '' order=data;
define growthDeclineColumn / group '' order = data;
define perGrowthDeclineColumn / group '' order = data;
define academic_period_desc / across '' order=data;

define n / analysis sum '' FORMAT=comma8.;

compute before growthDeclineColumn;
h1 = growthdeclinecolumn;

endcomp;
compute before perGrowthDeclineColumn;
h2 = perGrowthDeclineColumn;

endcomp;

compute gender_desc;
if h1 eq 1 then call define(_row_,'style','style={font_weight=bold}');
if h2 eq 1 then call define(_col_,'style','style={font_weight=bold}');
endcomp;

Discussion stats
• 11 replies
• 1771 views
• 3 likes
• 3 in conversation