proc report

Reply
Frequent Contributor
Posts: 115

proc report

am writing a proc report with below case

data xx;

input var1 $4. var2 $3. num1 num2 ;

datalines4;

REG1         3 4

REG1 CU1  1 2

REG1 CU2  1 5

;;;;

I need below output by using proc report to fulfil for my requirement. I need sum of var2 column (all CU1 and CU2) under REG1, not empty var2

Output;

REG1          3  4

    CU1        1  2

    CU2        1  5

Sum of       2   7

Var2

SAS Super FREQ
Posts: 8,743

Re: proc report

Hi:

It looks to me like you want the sum of NUM1 and NUM2 for those rows where VAR2 has a value (CU1, CU2).  Since VAR2 is a character variable, you can get the count, but not the sum of character variables.

 

  What PROC REPORT code have you tried? Generally, PROC REPORT will try to add up all of the NUM1 and NUM2 values on every row. You could adjust this in a COMPUTE block by testing for the value of VAR2 and then creating a temporary variable to use at the break/rbreak to adjust the final amount.

cynthia

Frequent Contributor
Posts: 115

Re: proc report


Sum of var2 is a text (i.e. sum of all CU's)  want to display this text for each group at end of the REGx.

Input:

Var1  Var2 Num1  Num2

REG1         3         4

REG1 CU1  1        2

REG1 CU2  1        5

REG2         1       1

REG2 CU3  2        1

REG2 CU5  3        1

1) Output:

Blank name          Var1 Var2

REG1                       3  4

    CU1                      1  2

    CU2                      1  5

REG1 Total Cu's       2  7

REG2                       1  1

REG2 CU3               2  1

REG2 CU5               3  1

REG2 Total Cu's       2  7

Frequent Contributor
Posts: 115

Re: proc report

small correction in required output. could any one able to help me to get below output

Sum of var2 is a text (i.e. sum of all CU's)  want to display this text for each group at end of the REGx. 

Input:

Var1  Var2 Num1  Num2

REG1         3         4

REG1 CU1  1        2

REG1 CU2  1        5

REG2         1       1

REG2 CU3  2        1

REG2 CU5  3        1

1) Output:

Blank name          Var1 Var2

REG1                       3  4

    CU1                     1  2

    CU2                     1  5

REG1 Total Cu's      2  7

REG2                       1  1

    CU3                     2  1

    CU5                     3  1

REG2 Total Cu's       5  2

SAS Super FREQ
Posts: 8,743

Re: proc report

Hi:

  What PROC REPORT code have you tried? I don't see a difference between your two posts in what you want. Can you clarify?

  You did not say what type of output you wanted to get: a dataset or a report. If you want a report, then what is your destination of choice? If you want the values in the first row (for REG1 and REG2) in red, then that cannot be done in the LISTING destination output.

  Next, you show the values of VAR1, (REG1 and REG2) only appearing 1 time, and the values for VAR2 look like they are slightly indented. Is this what you want? Again, you cannot get that type of indention in LISTING output.

  Seeing the PROC REPORT code you've tried will be helpful? Did you define VAR1 and VAR2 as DISPLAY or ORDER items? What statistic did you use for NUM1 and NUM2? What is your BREAK statement? What is your COLUMN statement? What COMPUTE block logic did you try to adjust the total at the break?

cynthia

Frequent Contributor
Posts: 115

Re: proc report

Hi Cynthia,

Thanks for your time in this.

I am using below proc report to fulfil for one of my requirement.

data test1;
input var1 $5. var2 $4. num1 num2 ;
datalines4;
REG1      3 4
REG1 CU1  1 2
REG1 CU2  1 5

;;;;


proc report data=test1 nowd split='#'
    style(report)={just=left rules=none frame=void cellspacing=0}
    style(header)={just=left background=verydarkblue color=white font_weight=bold}
  style(column)={just=left background=white cellspacing=0pt font_size=10pt font_weight=medium font_face="Arial"} split='*' ;

column var1 var2 num1 num2;

define var1 / group display order order=data ' ' ;
   
define num1/analysis;
define num2/analysis;
break after var1 / ol skip summarize suppress;
compute after var1;
  var1='Totcu';
endcomp;
run;

I want to generate a report, and i need to calculate the sum of all Var2 except row, which blank in var2 column. these sum i have to use at end of each Regx. I want to display 1 time for each REGx(which contains empty in Var2 column always).

I am not able to get desired output by using above code. Could you please able to help me in this


Ask a Question
Discussion stats
  • 5 replies
  • 355 views
  • 0 likes
  • 2 in conversation