The SAS Output Delivery System and reporting techniques

Proc report and conditional count

Contributor sks
Posts: 42

Proc report and conditional count

Hello all,
I am trying to build a cross tab report using proc report. In the report I need to get an overall count of records and a count of records with a field ='Y' and then display them next to each other. Let me show you how the data is and what the report should look like

r_type b_type r_amt int_type int_amt
aaa 1111 $10 N 0
aaa 1111 $30 Y $10

aaa 2222 $50 Y $30

bbbb 1111 $15 Y $25

My report needs to look like

r_type b_type b_type_ct b_type_sum int_type_ct int_amt_sum
aaa 1111 2 $40 1 $10
aaa 222 1 $50 1 $30
bbb 1111 1 $15 1 $25

I Have been able to get the b_type_ct and b_type_sum I am using across to get those. But I don't know how to count only the rows with int_type='Y' and then get the sum of int_amt_sum for those rows. I am thinking I need to use some kind of compute block, Please can anyone give me some suggestions on how to do this,

Posts: 9,364

Re: Proc report and conditional count

This looks like a SUMMARY report -- but I do not see INT_TYPE on the report. Unless you put INT_TYPE on the report, it will be very hard to find the count for the INT_TYPE=Y. Is there a reason you don't want to see the count of the Y and the S or the total of the amount for the Y and the S???

PROC REPORT can only count or "work with" items that are placed on the report row. Can you show the code that you've started with??? And any log messages that you've gotten??

Frequent Contributor
Posts: 93

Proc report and conditional count

I would like an answer to this question too.

But for now, I change the Y/N character column into 1/0 numeric column. IF  int_type = 'Y' THEN  int_type_flag = 1 ELSE 0;

Then I use this code

proc report data=in;

column r_type b_type int_type_flag;

define r_type b_type/ group;

define int_type_flag / analysis SUM;


Posts: 9,364

Proc report and conditional count


  Can you show all the code that you are using so far, including the code that you have used to create int_type_flag???


Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation