BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DavidPhillips2
Rhodochrosite | Level 12

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
1 ACCEPTED SOLUTION

Accepted Solutions
DavidPhillips2
Rhodochrosite | Level 12

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

View solution in original post

11 REPLIES 11
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

DavidPhillips2
Rhodochrosite | Level 12

Tried both with no luck.

DavidPhillips2
Rhodochrosite | Level 12

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;

DavidPhillips2
Rhodochrosite | Level 12

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.

DavidPhillips2
Rhodochrosite | Level 12

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

DavidPhillips2
Rhodochrosite | Level 12

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

DavidPhillips2
Rhodochrosite | Level 12

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

DavidPhillips2
Rhodochrosite | Level 12

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

DavidPhillips2
Rhodochrosite | Level 12

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.

data_null__
Jade | Level 19

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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