## Proc Report

Solved
Super Contributor
Posts: 1,041

# Proc Report

HI TEAM

I got the following 2 variables after running a macro step for calculating Means and Freqs

Now I want to prepare a report with breaks after AGE BMI and GENDER.

I know how to go with it if they are coming from different datasets.But in this case I am not sure.

Any help is greatly appreciated

Demographics       count

Age                          .

Mean                      value

Median                   value

Range                     value

BMI                          .

Mean                      value

Median                   value

Range                     value

Gender

Female                    value

Male                        value

I WANT LIKE SHOWN BELOW

Demographics       count

Age                          .

Mean value

Median                   value

Range                     value

BMI                          .

Mean                      value

Median                   value

Range                     value

Gender

Female                    value

Male                        value

Accepted Solutions
Solution
‎10-09-2012 04:45 AM
Super User
Posts: 10,787

## Re: Proc Report

But your Data is almost like the report . Do you want this ?

```data x;
input Demographics     \$  count;
if missing(count) then group+1;
cards;
Age                          .
Mean                      2
Median                   2
Range                     2
BMI                          .
Mean                      2
Median                   2
Range                     2
Gender                    .
Female                    2
Male                        2
;
run;
ods listing close;
ods html file='c:\x.html' style=sasweb ;
proc report data=x nowd;
column group Demographics  count;
define group/group noprint;
compute after group;
line ' ';
endcomp;
run;
ods html close;
ods listing;
```

Ksharp

All Replies
Solution
‎10-09-2012 04:45 AM
Super User
Posts: 10,787

## Re: Proc Report

But your Data is almost like the report . Do you want this ?

```data x;
input Demographics     \$  count;
if missing(count) then group+1;
cards;
Age                          .
Mean                      2
Median                   2
Range                     2
BMI                          .
Mean                      2
Median                   2
Range                     2
Gender                    .
Female                    2
Male                        2
;
run;
ods listing close;
ods html file='c:\x.html' style=sasweb ;
proc report data=x nowd;
column group Demographics  count;
define group/group noprint;
compute after group;
line ' ';
endcomp;
run;
ods html close;
ods listing;
```

Ksharp

Valued Guide
Posts: 653

## Re: Proc Report

Here is a start.  The key is to have a dummy variable (TYPE - which for clarity here I have added in a separate DATA step) that can be used with a compute block.

data have;
input Demographics \$  count;
datalines;
Age                 .
Mean                25
Median              24
Range               35
BMI                 .
Mean                780
Median              777
Range               450
Gender               .
Female              5
Male                7
run;

data have2;
set have;
if demographics in('Age','BMI','Gender') then type+1;
run;

proc report data=have2 nowd;
column type demographics count;
define type / order noprint;
define demographics / display;
define count / display 'Value';
compute after type;
line ' ';
endcomp;
run;

Vertically concatenated tables such as this one pose a challenge in REPORT, and usually require some preprocessing such as was done here.  There are some examples of variations in the PROC REPORT book.

Super Contributor
Posts: 1,041

## Re: Proc Report

Thanks a ton.

This method works fine. Also how to get the headers alone to be in Bold letters(I mean with a bigger fiont)....

In the above example it would be like

Age                 .

Mean                25

Median              24

Range               35

BMI                 .

Mean                780

Median              777

Range               450

Gender               .

Female              5

Male                7

Valued Guide
Posts: 653

## Re: Proc Report

To conditionally change text attributes use the CALL DEFINE routine.  Replace Ksharp's REPORT step with the following.

proc format;
value misswd
. = ' '
other=[best12.];
run;
proc report data=x nowd;
column group Demographics  count;
define group/group noprint;
define demographics / order order=data;
define count / analysis format=misswd.;
compute count;
if count.sum=. then call define(_row_,'style','style={font_weight=bold font_size=14}');
endcomp;

compute after group;
line ' ';
endcomp;
run;

Super Contributor
Posts: 1,041

## Re: Proc Report

Hi,

I replaced Ksharps Proc report with the one you provided.

Interstingly, I get it like this.

1) The BMI header went beneath the group when it has to be on the top!!!!

2)Secondly, you applied the misswd. format on the count variable and where ever the missing (.) value is present its changed to a blank.

After that in the compute step you used :

if count.sum=.

we have changed the missing(.) count to a missing blank in the prior step. How can we say now if count.sum=.    ????????

Could you also please elaborate on this step on how this is changing the font of the header of the group????

Thanks

Age

Mean                2

Median             2

Range              2

Mean                2

Median             2

Range              2

BMI

Gender

Female             2

Male                 2

Contributor
Posts: 21

## Re: Proc Report

1) The BMI header went beneath the group when it has to be on the top!!!!

get rid of order=data it messed up the displaying order.

2)Secondly, you applied the misswd. format on the count variable and where ever the missing (.) value is present its changed to a blank.

After that in the compute step you used :

if count.sum=.

we have changed the missing(.) count to a missing blank in the prior step. How can we say now if count.sum=.    ????????

I would use option missing='' to change the . to blank. instead of defining the format.

Could you also please elaborate on this step on how this is changing the font of the header of the group????

if you are working on the list destination, i don't think you can change the font like what you just described. i might be wrong on this. what i have seen or used before is to send the output the destinations other than list so that you can use style overwrites or redefine template to manipulate the display.

please notice below, i use ORDER for group item. and for demographics I used display. really it doesn't matter for count variable, ether display or analysis will work.  you can not use the order or group for demographic as it will sort the data alphabetically.

data x;

input Demographics     \$  count;

if missing(count) then group+1;

cards;

Age                          .

Mean                      2

Median                   2

Range                     2

BMI                          .

Mean                      2

Median                   2

Range                     2

Gender                    .

Female                    2

Male                        2

;

run;

option missing='';

ods html;

proc report data=x nowd ;

column group Demographics  count;

define group/order noprint;

define demographics /display;

define count / analysis ;

compute Demographics ;

if  Demographics in ('Age' 'BMI' 'Gender') then call define(_row_,'style','style={font_weight=bold font_size=14}');

endcomp;

compute after group;

line ' ';

endcomp;

run;

ods html close;

Super Contributor
Posts: 1,041

## Re: Proc Report

Hi,

Except for the BMI order the others are right.

I was wondering how could they use :

if count.sum=. then call define(_row_,'style','style={font_weight=bold font_size=14}') after the missing values were changed to a balank(" ")

What does the sum have to do here????

Regards

Super User
Posts: 10,787

## Re: Proc Report

Arthur use count.sum because he use define count / analysis  . which means it is analysis usage(the defalut statistical estimator is SUM).

You can also use count when you specify define count / display .

Here Arthur only use a customize format to display missing value as a blank , while the actual value is still missing .

```data x;
input Demographics     \$  count;
if missing(count) then group+1;
cards;
Age                          .
Mean                      2
Median                   2
Range                     2
BMI                          .
Mean                      2
Median                   2
Range                     2
Gender                    .
Female                    2
Male                        2
;
run;
ods listing close;
ods html file='c:\x.html' style=sasweb ;
options missing=' ';
proc report data=x nowd;
column group Demographics  count;
define group/group noprint;
define count/display;
compute after group;
line ' ';
endcomp;
compute  count;
if missing(count) then call define(_row_,'style','style={font_weight=bold font_size=14}');
endcomp;
run;
ods html close;
ods listing;

```

Ksharp

Super User
Posts: 10,787

## Re: Proc Report

Ha. You need to read REPORT documention more .

"but confused with why the actual value will be still a missing . when we applied a " " on that same variable;"

It is always missing value whatever you use . or ' ' or '1'  or '2' or something else to display .

FORMAT is only the cloth of value .

About count.sum , it refer to count column .

when count column use ANALYSIS usage and SUM(default) .you should use count.sum to represent it.

And when count column use DISPLAY usage .you should use count to represent it .

Super Contributor
Posts: 1,041

## Re: Proc Report

hi,

Thanks for the detailed explanation.

I started with the Proc Report .But have to continue to read....

Also when i write for example  :

if missing(any variable name)

can the missing be use for  variables with numeric missing as well as variables with missing charecter values???

Thanks

Super User
Posts: 10,787

## Re: Proc Report

Yes . It is common to both numeric and character.

But there are something you need to remind .

if missing(count)    <---- suited for both numeric and character

if missing(count.sum)  <---only suited for numeric , because it must be numeric type varible .

Can find the difference of these ? with my last post .

Ksharp

Super Contributor
Posts: 1,041

## Re: Proc Report

Hi,

Thanks for the help.

For example

Wt.sum  has 2 meanings .

1)Meaning 1 when it is used with a GROUP variable then it holds the total weights

2)Meaning 2 when it used with a DETAIL ROW it holds the value of the weight for that ROW alone

Cheers

Super Contributor
Posts: 1,041

## Re: Proc Report

I understand your logic that where ever it is ('Age' 'BMI' 'Gender' ) you are using call define for that row with that style.

Am i right???

Thanks

🔒 This topic is solved and locked.

Discussion stats
• 13 replies
• 485 views
• 6 likes
• 4 in conversation