DATA Step, Macro, Functions and more

Using compute in PROC REPORT with subcolumns

Accepted Solution Solved
Reply
Occasional Contributor nd
Occasional Contributor
Posts: 6
Accepted Solution

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
 12
 sexsexsexsex
 MaleFemaleMaleFemale
CONTRASTpvalpvalpvalpval
Latino vs. non-Latino<0.0010.0020.0060.001
US born vs FB0.5890.0560.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: 11,343

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;

View solution in original post


All Replies
Solution
‎04-12-2017 04:37 PM
Super User
Posts: 11,343

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 nd
Occasional Contributor
Posts: 6

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. Smiley Sad

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 183 views
  • 0 likes
  • 2 in conversation