## Using compute in PROC REPORT with subcolumns

Solved
Occasional Contributor
Posts: 8

# Using compute in PROC REPORT with subcolumns

Using SUDAAN's proc descript I outputted a dataset that contains p-values. I would like to create a report that shows the p-values rounded to 3 decimals places by sex (in the dataset it's 4 decimal places). The report should look like this:

 Variable 1 2 sex sex sex sex Male Female Male Female CONTRAST pval pval pval pval Latino vs. non-Latino <0.001 0.002 0.006 0.001 US born vs FB 0.589 0.056 0.005 <0.001

However, I'm running into a couple of issues:

1) When I try to use a format statement to round, if, for example, a p-value is 0.0009 it's incorrectly printed as "<0.001" instead of "0.001."

```proc format;
value pv
0-<0.001='<0.001'
other=[5.3];
run;proc report data=tt nowindows ; column (contrast) variable, sex, (p_pct) ; define contrast / group format=test. order=internal ; define variable / across nozero order=internal ; define sex / 'sex' across nozero order=internal ; define p_pct / 'pval' format=pv. ;run;```

2) As a workaround I tried using a compute block, However I can't get my subcolumns. When I use this code

```proc report data=tt  nowindows ;
column (contrast) variable, sex, (p_pct pval) ;
define contrast / group format=test. order=internal ;
define variable / across nozero order=internal ;
define sex / 'sex' across nozero  order=internal ;
define p_pct /  noprint ;
define pval / computed format=pv.;
compute pval;
pval=round(p_pct,0.001);
endcomp;
where contrast in (1:6,17);
run;```

I get an error message: ERROR: Variable p_pct is uninitialized

This code works but sex is no longer a column header and I don't want to display p_pct, only pval.

```proc report data=tt  nowindows ;
column (contrast) variable, sex p_pct pval  ;
define contrast / group format=test. order=internal ;
define variable / across nozero order=internal ;
define sex / 'sex'  nozero  order=internal ;
define p_pct / 'p_pct' display ;
define pval / computed format=pv.;
compute pval;
pval=round(p_pct,0.001);
endcomp;
where contrast in (1:6,17);
run;```

Any assistance would be helpful. Thanks!

P.S. Using SAS 9.4

Accepted Solutions
Solution
‎04-12-2017 04:37 PM
Super User
Posts: 13,941

## Re: Using compute in PROC REPORT with subcolumns

Since your format said 0-<0.001 = '<0.001' and the value you mention is 0.0009 it is doing what you told it.

You would have to manually round before applying the format. Note that SAS supplies a PVALUE format you can use.

```data example;
x= 0.0009;
put x= pvalue6.3;
x= round(x,0.001);
put x= pvalue6.3;
run;```

All Replies
Solution
‎04-12-2017 04:37 PM
Super User
Posts: 13,941

## Re: Using compute in PROC REPORT with subcolumns

Since your format said 0-<0.001 = '<0.001' and the value you mention is 0.0009 it is doing what you told it.

You would have to manually round before applying the format. Note that SAS supplies a PVALUE format you can use.

```data example;
x= 0.0009;
put x= pvalue6.3;
x= round(x,0.001);
put x= pvalue6.3;
run;```
Occasional Contributor
Posts: 8

## Re: Using compute in PROC REPORT with subcolumns

Thanks. I was afraid that I would need a dataset; was hoping that using a compute block could be a workaround.

☑ This topic is solved.