Help using Base SAS procedures

Proc report - COMPUTE BEFORE _PAGE_

Accepted Solution Solved
Reply
Occasional Contributor VS
Occasional Contributor
Posts: 15
Accepted Solution

Proc report - COMPUTE BEFORE _PAGE_

Hi,

I sent my question a few days ago (without data and a full code) about my problem with COMPUTE BEFORE block in PROC REPORT.

When I used just COMPUTE BEFORE, calculated fields were correct but displayed between data and row headings. I found in some article that to get them in the right place (above the data) I had to use COMPUTE BEFORE _PAGE_. However, when I did that the fields moved to the right place, but the calculated values did not display.

As Cynthia suggested, I've attached my code and test data.

I will appreciate any advice re my problem and any other suggestions about the code.

Thank you

Victoria

Attachment
Attachment

Accepted Solutions
Solution
‎11-11-2014 10:10 PM
SAS Super FREQ
Posts: 8,864

Re: Proc report - COMPUTE BEFORE _PAGE_

Hi:

  I was expecting to see a date on every row and considered it an error condition that there weren't more values. And, asking for any date.sum to be be used in a LINE doesn't make sense to me. Also, since there ARE fields with a 1 on every row for the Number value, I wondered whether the wrong column was being number of LL2 and LL3 flags. And, even if the COMPUTE BEFORE break-var does shown something for the date1 field, there is nothing for date2 and date3, which was what led me to believe that all 3 date values were wrong or off.

  PROC REPORT goes through a pre-processing summarization phase when it starts. I'm not sure whether you've stumbled on a timing issue or not. Consider the code that simplifies the example and output it produces shown in the screen shot below. Clearly, what is available for COMPUTE BEFORE _PAGE_ is different than the COMPUTE BEFORE or COMPUTE AFTER. This may be PROC REPORT working as designed. In which case, the OP needs to come up with a different solution what they are trying to do.

Cynthia

data testit;

  set sashelp.class;

  where age in (13, 14, 15);

  if sex = 'M' then numboy = 1;

  else if sex = 'F' then numgirl = 1;

run;

   

ods html file='c:\temp\testit.html';

proc report data=testit nowd

  style(summary)=Header;

  column age sex numboy numgirl name height weight;

  define age / order;

  break after age / summarize;

  rbreak after / summarize;

  compute before _page_;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

  compute after;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

  compute before;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

run;

ods html close;


show_compute_before_page_avail.png

View solution in original post


All Replies
Super User
Posts: 10,023

Re: Proc report - COMPUTE BEFORE _PAGE_

Code worked for me . It looks like f2 f3 date2_1 ......... they are all missing.

data class;set sashelp.class;run;
proc sort data=class;by sex;run;

proc report data=class nowd;
by sex;
columns name age height weight ;
define name/display ;
define age/display ;
define height/analysis sum noprint;
define weight/analysis sum noprint;
compute before _page_;
line 'height' height.sum;
line 'weight' weight.sum;
endcomp;
run;


Xia Keshan

SAS Super FREQ
Posts: 8,864

Re: Proc report - COMPUTE BEFORE _PAGE_

Hi:

  Thanks for the code. You left off some of the required pieces, like the user-defined formats and the %RGB macro. But a quick look at your data does reveal that many of the date fields that you are trying to use in your COMPUTE BEFORE are all missing values. But, as Xia's example shows, in practice, with different data, the values for a summarized analysis item are available in the COMPUTE BEFORE _PAGE_. The only conclusion possible is that you have a problem with your data or your assumptions about the data. Here's what I see when I look at the data file you sent. F2 and F3 that you are trying to display at the COMPUTE are all missing and the DATE variables you are trying to display at the COMPUTE are all missing.

  I'd recommend taking a step back and getting the COMPUTE BEFORE _PAGE_ working for a simpler example and then trying a more complex example. Or, you could try working with Tech Support, but I would really recommend taking a closer look at the data and the pre-processing data manipulation you're trying to do. Somehow, I don't think that you are accomplishing what you want to accomplish. And, in looking at your data file, it's not obvious what you are trying to achieve.

cynthia


missing_values_in_test_data.png
Occasional Contributor VS
Occasional Contributor
Posts: 15

Re: Proc report - COMPUTE BEFORE _PAGE_

Posted in reply to Cynthia_sas

Hi,

I must be definitely missing something. As I can see it, data for dates and F2 and F3 is not missing. For example, there is a valid date and a corresponding F3  in row 106 (can be seen in Cynthia's image). Also there are values in rows 18, 61 and 74. My understanding is that COMPUTE block computes within BY-GROUP. In my case, within each BY-GROUP section there is at least one flag and a date associated with it.

With COMPUTE BEFORE, this precisely data gives me the correct result as in the first picture below,  but in a 'wrong' place .

The second image - with COMPUTE BEFORE _PAGE_ - shows all the text information in the 'right place', but the computed values are no longer there.

So I am not accomplishing what I want to accomplish, but I still cannot see why.

Image 1: With COMPUTE BEFORE

INF_Hosp1 with BEFORE.PNG

Image 2: With COMPUTE BEFORE _PAGE_

AMI_Hosp1 - with BEFORE _PAGE_.PNG

Solution
‎11-11-2014 10:10 PM
SAS Super FREQ
Posts: 8,864

Re: Proc report - COMPUTE BEFORE _PAGE_

Hi:

  I was expecting to see a date on every row and considered it an error condition that there weren't more values. And, asking for any date.sum to be be used in a LINE doesn't make sense to me. Also, since there ARE fields with a 1 on every row for the Number value, I wondered whether the wrong column was being number of LL2 and LL3 flags. And, even if the COMPUTE BEFORE break-var does shown something for the date1 field, there is nothing for date2 and date3, which was what led me to believe that all 3 date values were wrong or off.

  PROC REPORT goes through a pre-processing summarization phase when it starts. I'm not sure whether you've stumbled on a timing issue or not. Consider the code that simplifies the example and output it produces shown in the screen shot below. Clearly, what is available for COMPUTE BEFORE _PAGE_ is different than the COMPUTE BEFORE or COMPUTE AFTER. This may be PROC REPORT working as designed. In which case, the OP needs to come up with a different solution what they are trying to do.

Cynthia

data testit;

  set sashelp.class;

  where age in (13, 14, 15);

  if sex = 'M' then numboy = 1;

  else if sex = 'F' then numgirl = 1;

run;

   

ods html file='c:\temp\testit.html';

proc report data=testit nowd

  style(summary)=Header;

  column age sex numboy numgirl name height weight;

  define age / order;

  break after age / summarize;

  rbreak after / summarize;

  compute before _page_;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

  compute after;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

  compute before;

     line 'Compute before _page_';

     line 'Numboy = ' numboy.sum comma3.;

     line 'Numgirl = ' numgirl.sum comma3.;

     line 'Height = ' height.sum comma6.2;

     line 'Weight = ' weight.sum comma6.2;

  endcomp;

run;

ods html close;


show_compute_before_page_avail.png
Occasional Contributor VS
Occasional Contributor
Posts: 15

Re: Proc report - COMPUTE BEFORE _PAGE_

Posted in reply to Cynthia_sas

Thanks Cynthia,

It very helpful! Now it makes sense that COMPUTE BEFORE _PAGE_ reports only the first row in a BY-GROUP. And for my purpose it is not a limitation - it is a bonus! Because I've got other variables which hold all the information I need in each row. So I can just use those variables instead.

Thanks again, BEFORE _PAGE_ mystery solved.

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 654 views
  • 3 likes
  • 3 in conversation