BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
nd
Obsidian | Level 7 nd
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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

2 REPLIES 2
ballardw
Super User

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;
nd
Obsidian | Level 7 nd
Obsidian | Level 7

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

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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