Your SAS programs, embedded in web apps and elsewhere

Comparing Column Using Compute

Accepted Solution Solved
Reply
Super Contributor
Posts: 497
Accepted Solution

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.


growth.png

Accepted Solutions
Solution
‎07-15-2015 02:17 PM
Super Contributor
Posts: 497

Re: Comparing Column Using Compute

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

View solution in original post


All Replies
Super User
Super User
Posts: 7,977

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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...;

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Tried both with no luck.

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

Below is the full code.

data all;

   /*length GENDER_DESC $ 34;

   length ACADEMIC_PERIOD_DESC $ 9;*/

   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

Headcount Growth/(Decline),Fall 2010,.,1,0

Headcount Growth/(Decline),Fall 2011,-404.00,1,0

Headcount Growth/(Decline),Fall 2012,-147.00,1,0

Headcount Growth/(Decline),Fall 2013,-464.00,1,0

Headcount Growth/(Decline),Fall 2014,-125.00,1,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;

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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.

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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.

Super User
Super User
Posts: 7,977

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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.

Solution
‎07-15-2015 02:17 PM
Super Contributor
Posts: 497

Re: Comparing Column Using Compute

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

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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

Super Contributor
Posts: 497

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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.

Respected Advisor
Posts: 3,799

Re: Comparing Column Using Compute

Posted in reply to DavidPhillips2

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
Headcount Growth/(Decline),Fall 2010,.,1,0
Headcount Growth/(Decline),Fall 2011,-404.00,1,0
Headcount Growth/(Decline),Fall 2012,-147.00,1,0
Headcount Growth/(Decline),Fall 2013,-464.00,1,0
Headcount Growth/(Decline),Fall 2014,-125.00,1,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;

Capture.PNG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

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